Skip to content

Commit 74e8a5b

Browse files
committed
Add missing test cases
Now all combinations of keeping/changing filenames and file contents are covered.
1 parent d9fb5b0 commit 74e8a5b

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

pkg/operator/staticpod/certsyncpod/certsync_controller_test.go

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestWriteFiles(t *testing.T) {
127127
checkState: checkOnSuccess,
128128
},
129129
{
130-
name: "update target directory change file content",
130+
name: "change file contents preserving the filenames",
131131
newFS: newRealFS,
132132
directoryData: map[string][]byte{
133133
"tls.crt": []byte("TLS cert"),
@@ -140,7 +140,20 @@ func TestWriteFiles(t *testing.T) {
140140
checkState: checkOnSuccess,
141141
},
142142
{
143-
name: "update target directory change filenames",
143+
name: "change filenames preserving the file contents",
144+
newFS: newRealFS,
145+
directoryData: map[string][]byte{
146+
"tls.crt": []byte("TLS cert"),
147+
"tls.key": []byte("TLS key"),
148+
},
149+
objectData: map[string][]byte{
150+
"api.crt": []byte("TLS cert"),
151+
"api.key": []byte("TLS key"),
152+
},
153+
checkState: checkOnSuccess,
154+
},
155+
{
156+
name: "change filenames and file contents",
144157
newFS: newRealFS,
145158
directoryData: map[string][]byte{
146159
"tls.crt": []byte("TLS cert"),
@@ -152,6 +165,45 @@ func TestWriteFiles(t *testing.T) {
152165
},
153166
checkState: checkOnSuccess,
154167
},
168+
{
169+
name: "replace a single file content",
170+
newFS: newRealFS,
171+
directoryData: map[string][]byte{
172+
"1.txt": []byte("1"),
173+
"2.txt": []byte("2"),
174+
},
175+
objectData: map[string][]byte{
176+
"1.txt": []byte("1"),
177+
"2.txt": []byte("3"),
178+
},
179+
checkState: checkOnSuccess,
180+
},
181+
{
182+
name: "replace a single file",
183+
newFS: newRealFS,
184+
directoryData: map[string][]byte{
185+
"1.txt": []byte("1"),
186+
"2.txt": []byte("2"),
187+
},
188+
objectData: map[string][]byte{
189+
"1.txt": []byte("1"),
190+
"3.txt": []byte("3"),
191+
},
192+
checkState: checkOnSuccess,
193+
},
194+
{
195+
name: "rename a single file",
196+
newFS: newRealFS,
197+
directoryData: map[string][]byte{
198+
"1.txt": []byte("1"),
199+
"2.txt": []byte("2"),
200+
},
201+
objectData: map[string][]byte{
202+
"1.txt": []byte("1"),
203+
"3.txt": []byte("2"),
204+
},
205+
checkState: checkOnSuccess,
206+
},
155207
errorTestCase("directory unchanged on failed to create object directory", func() *fileSystem {
156208
fs := newRealFS()
157209
fs.MkdirAll = func(path string, perm os.FileMode) error {

0 commit comments

Comments
 (0)