Skip to content

Commit efbbd41

Browse files
committed
CheckDirectoryMarches: Ensure no files are missing
1 parent 83708b2 commit efbbd41

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/operator/staticpod/file_utils_linux_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"os"
88
"path/filepath"
99
"testing"
10+
11+
"github.com/google/go-cmp/cmp"
12+
"k8s.io/apimachinery/pkg/util/sets"
1013
)
1114

1215
func TestSwapDirectoriesAtomic(t *testing.T) {
@@ -156,7 +159,11 @@ func (dir directoryState) CheckDirectoryMatches(t *testing.T, path string) {
156159
t.Fatalf("Failed to read directory %q: %v", path, err)
157160
}
158161

162+
expectedFiles := sets.KeySet(dir)
159163
for _, entry := range entries {
164+
// Mark the file as visited.
165+
expectedFiles.Delete(entry.Name())
166+
160167
// Get the expected state.
161168
state, ok := dir[entry.Name()]
162169
if !ok {
@@ -182,7 +189,10 @@ func (dir directoryState) CheckDirectoryMatches(t *testing.T, path string) {
182189
continue
183190
}
184191
if !bytes.Equal(state.Content, content) {
185-
t.Errorf("Unexpected content on file %q:\n\texpected %v\n\tgot %v", entry.Name(), string(state.Content), string(content))
192+
t.Errorf("Unexpected content in file %q:\n%v", entry.Name(), cmp.Diff(string(state.Content), string(content)))
186193
}
187194
}
195+
if expectedFiles.Len() != 0 {
196+
t.Errorf("Some expected files were not found in directory %q: %s", path, expectedFiles.UnsortedList())
197+
}
188198
}

0 commit comments

Comments
 (0)