-
Notifications
You must be signed in to change notification settings - Fork 30
/
backupstore_test.go
107 lines (101 loc) · 4.01 KB
/
backupstore_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package backupstore
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncodeAndDecodeBackupURL(t *testing.T) {
testCases := []struct {
volumeName string
backupName string
destURL string
expectDecodeError bool
expectBackupURL string
expectDecodeURL string
}{
{
volumeName: "vol-1",
destURL: "s3://backupstore@minio/",
expectBackupURL: "s3://backupstore@minio/?volume=vol-1",
expectDecodeURL: "s3://backupstore@minio/",
},
{
volumeName: "vol-2",
backupName: "backup-2",
destURL: "s3://backupstore@minio/",
expectBackupURL: "s3://backupstore@minio/?backup=backup-2&volume=vol-2",
expectDecodeURL: "s3://backupstore@minio/",
},
{
// Test invalid volume name
volumeName: "-3-vol",
destURL: "s3://backupstore@minio/",
expectBackupURL: "s3://backupstore@minio/?volume=-3-vol",
expectDecodeError: true,
},
{
// Test invalid backup name
volumeName: "vol-4",
backupName: "-4-backup",
destURL: "s3://backupstore@minio/",
expectBackupURL: "s3://backupstore@minio/?backup=-4-backup&volume=vol-4",
expectDecodeError: true,
},
{
// Test NFS target with no mount options.
volumeName: "vol-5",
backupName: "backup-5",
destURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore",
expectBackupURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?backup=backup-5&volume=vol-5",
expectDecodeURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore",
},
{
// Test NFS target with mount options (simple form). Query tags are sorted, "=" and "," are escaped.
volumeName: "vol-6",
backupName: "backup-6",
destURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=soft,timeo=150,retrans=3",
expectBackupURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?backup=backup-6&nfsOptions=soft%2Ctimeo%3D150%2Cretrans%3D3&volume=vol-6",
expectDecodeURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=soft%2Ctimeo%3D150%2Cretrans%3D3",
},
{
// Test NFS target with mount options (other form).
volumeName: "vol-6",
backupName: "backup-6",
destURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=soft&nfsOptions=timeo=150&nfsOptions=retrans=3",
expectBackupURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?backup=backup-6&nfsOptions=soft&nfsOptions=timeo%3D150&nfsOptions=retrans%3D3&volume=vol-6",
expectDecodeURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=soft&nfsOptions=timeo%3D150&nfsOptions=retrans%3D3",
},
{
// Test NFS target with empty Query tag.
volumeName: "vol-7",
backupName: "backup-7",
destURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?",
expectBackupURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?backup=backup-7&volume=vol-7",
expectDecodeURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore",
},
{
// Test NFS target with empty mount options.
volumeName: "vol-8",
backupName: "backup-8",
destURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=",
expectBackupURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?backup=backup-8&nfsOptions=&volume=vol-8",
expectDecodeURL: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore?nfsOptions=",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s%s&%s", tc.destURL, tc.backupName, tc.volumeName), func(t *testing.T) {
assert := assert.New(t)
gotBackupURL := EncodeBackupURL(tc.backupName, tc.volumeName, tc.destURL)
assert.Equal(tc.expectBackupURL, gotBackupURL)
backupName, volumeName, destURL, err := DecodeBackupURL(gotBackupURL)
if tc.expectDecodeError {
assert.NotNil(err)
} else {
assert.Nil(err)
assert.Equal(tc.backupName, backupName)
assert.Equal(tc.volumeName, volumeName)
assert.Equal(tc.expectDecodeURL, destURL)
}
})
}
}