-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathbackupvars_test.go
More file actions
161 lines (146 loc) · 4.07 KB
/
Copy pathbackupvars_test.go
File metadata and controls
161 lines (146 loc) · 4.07 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package backuphelpers
import (
"testing"
backupv1alpha1 "github.com/openshift/api/config/v1alpha1"
prune "github.com/openshift/cluster-etcd-operator/pkg/cmd/prune-backups"
"github.com/stretchr/testify/require"
)
const (
schedule = "0 */2 * * *"
timezone = "GMT"
)
func TestBackupConfig_ToArgs(t *testing.T) {
testCases := []struct {
name string
cr *backupv1alpha1.EtcdBackupSpec
expected string
}{
{
"backup spec with timezone and schedule",
createEtcdBackupSpec(timezone, schedule),
" args:\n - --enabled=true\n - --timezone=GMT\n - --schedule=0 */2 * * *",
},
{
"backup spec with timezone and empty schedule",
createEtcdBackupSpec(timezone, ""),
" args:\n - --enabled=true\n - --timezone=GMT",
},
{
"backup spec with empty timezone and schedule",
createEtcdBackupSpec("", schedule),
" args:\n - --enabled=true\n - --schedule=0 */2 * * *",
},
{
"backup spec with timezone and schedule and retention number",
withRetentionNumberThreeBackups(createEtcdBackupSpec(timezone, schedule)),
" args:\n - --enabled=true\n - --timezone=GMT\n - --schedule=0 */2 * * *\n - --type=RetentionNumber\n - --maxNumberOfBackups=3",
},
{
"backup spec with timezone and schedule and retention size",
withRetentionSizeOneGB(createEtcdBackupSpec(timezone, schedule)),
" args:\n - --enabled=true\n - --timezone=GMT\n - --schedule=0 */2 * * *\n - --type=RetentionSize\n - --maxSizeOfBackupsGb=1",
},
{
"backup spec with empty timezone and empty schedule",
nil,
" args:\n - --enabled=false",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
c := NewDisabledBackupConfig()
c.SetBackupSpec(tc.cr)
act := c.ArgString()
require.Equal(t, tc.expected, act)
})
}
}
func TestBackupConfig_ToArgList(t *testing.T) {
testCases := []struct {
name string
cr *backupv1alpha1.EtcdBackupSpec
expected []string
}{
{
"backup spec with timezone and schedule",
createEtcdBackupSpec(timezone, schedule),
[]string{
"--enabled=true",
"--timezone=GMT",
"--schedule=0 */2 * * *",
},
},
{
"backup spec with timezone and empty schedule",
createEtcdBackupSpec(timezone, ""),
[]string{
"--enabled=true",
"--timezone=GMT",
},
},
{
"backup spec with empty timezone and schedule",
createEtcdBackupSpec("", schedule),
[]string{
"--enabled=true",
"--schedule=0 */2 * * *",
},
},
{
"backup spec with timezone and schedule and retention number",
withRetentionNumberThreeBackups(createEtcdBackupSpec(timezone, schedule)),
[]string{
"--enabled=true",
"--timezone=GMT",
"--schedule=0 */2 * * *",
"--type=RetentionNumber",
"--maxNumberOfBackups=3",
},
},
{
"backup spec with timezone and schedule and retention size",
withRetentionSizeOneGB(createEtcdBackupSpec(timezone, schedule)),
[]string{
"--enabled=true",
"--timezone=GMT",
"--schedule=0 */2 * * *",
"--type=RetentionSize",
"--maxSizeOfBackupsGb=1",
},
},
{
"backup spec with empty timezone and empty schedule",
nil,
[]string{
"--enabled=false",
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
c := NewDisabledBackupConfig()
c.SetBackupSpec(tc.cr)
require.Equal(t, tc.expected, c.ArgList())
})
}
}
func createEtcdBackupSpec(timezone, schedule string) *backupv1alpha1.EtcdBackupSpec {
return &backupv1alpha1.EtcdBackupSpec{
Schedule: schedule,
TimeZone: timezone,
}
}
func withRetentionNumberThreeBackups(b *backupv1alpha1.EtcdBackupSpec) *backupv1alpha1.EtcdBackupSpec {
b.RetentionPolicy.RetentionType = prune.RetentionTypeNumber
b.RetentionPolicy.RetentionNumber = &backupv1alpha1.RetentionNumberConfig{
MaxNumberOfBackups: 3,
}
return b
}
func withRetentionSizeOneGB(b *backupv1alpha1.EtcdBackupSpec) *backupv1alpha1.EtcdBackupSpec {
b.RetentionPolicy.RetentionType = prune.RetentionTypeSize
b.RetentionPolicy.RetentionSize = &backupv1alpha1.RetentionSizeConfig{
MaxSizeOfBackupsGb: 1,
}
return b
}