Skip to content

Commit 59b7cb0

Browse files
committed
Add more test cases
1 parent f12253c commit 59b7cb0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

pkg/operator/staticpod/certsyncpod/certsync_controller_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,29 @@ func TestWriteFiles(t *testing.T) {
120120
},
121121
checkState: checkOnSuccess,
122122
},
123+
{
124+
name: "target directory is empty",
125+
newFS: newRealFS,
126+
directoryData: map[string][]byte{},
127+
objectData: map[string][]byte{
128+
"tls.crt": []byte("TLS cert"),
129+
"tls.key": []byte("TLS key"),
130+
},
131+
checkState: checkOnSuccess,
132+
},
133+
{
134+
name: "target directory already synchronized",
135+
newFS: newRealFS,
136+
directoryData: map[string][]byte{
137+
"tls.crt": []byte("TLS cert"),
138+
"tls.key": []byte("TLS key"),
139+
},
140+
objectData: map[string][]byte{
141+
"tls.crt": []byte("TLS cert"),
142+
"tls.key": []byte("TLS key"),
143+
},
144+
checkState: checkOnSuccess,
145+
},
123146
{
124147
name: "change file contents preserving the filenames",
125148
newFS: newRealFS,
@@ -198,6 +221,43 @@ func TestWriteFiles(t *testing.T) {
198221
},
199222
checkState: checkOnSuccess,
200223
},
224+
{
225+
name: "add new files",
226+
newFS: newRealFS,
227+
directoryData: map[string][]byte{
228+
"tls.crt": []byte("TLS cert"),
229+
"tls.key": []byte("TLS key"),
230+
},
231+
objectData: map[string][]byte{
232+
"tls.crt": []byte("TLS cert"),
233+
"tls.key": []byte("TLS key"),
234+
"another_tls.crt": []byte("another TLS cert"),
235+
"another_tls.key": []byte("another TLS key"),
236+
},
237+
checkState: checkOnSuccess,
238+
},
239+
{
240+
name: "delete a single file",
241+
newFS: newRealFS,
242+
directoryData: map[string][]byte{
243+
"1.txt": []byte("1"),
244+
"2.txt": []byte("2"),
245+
},
246+
objectData: map[string][]byte{
247+
"1.txt": []byte("1"),
248+
},
249+
checkState: checkOnSuccess,
250+
},
251+
{
252+
name: "delete all files",
253+
newFS: newRealFS,
254+
directoryData: map[string][]byte{
255+
"1.txt": []byte("1"),
256+
"2.txt": []byte("2"),
257+
},
258+
objectData: map[string][]byte{},
259+
checkState: checkOnSuccess,
260+
},
201261
errorTestCase("directory unchanged on failed to create object directory", func() *fileSystem {
202262
fs := newRealFS()
203263
fs.MkdirAll = func(path string, perm os.FileMode) error {

0 commit comments

Comments
 (0)