7
7
"os"
8
8
"path/filepath"
9
9
"testing"
10
+
11
+ "github.com/google/go-cmp/cmp"
12
+ "k8s.io/apimachinery/pkg/util/sets"
10
13
)
11
14
12
15
func TestSwapDirectoriesAtomic (t * testing.T ) {
@@ -156,7 +159,11 @@ func (dir directoryState) CheckDirectoryMatches(t *testing.T, path string) {
156
159
t .Fatalf ("Failed to read directory %q: %v" , path , err )
157
160
}
158
161
162
+ expectedFiles := sets .KeySet (dir )
159
163
for _ , entry := range entries {
164
+ // Mark the file as visited.
165
+ expectedFiles .Delete (entry .Name ())
166
+
160
167
// Get the expected state.
161
168
state , ok := dir [entry .Name ()]
162
169
if ! ok {
@@ -182,7 +189,10 @@ func (dir directoryState) CheckDirectoryMatches(t *testing.T, path string) {
182
189
continue
183
190
}
184
191
if ! bytes .Equal (state .Content , content ) {
185
- t .Errorf ("Unexpected content on file %q:\n \t expected %v \n \t got %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 ) ))
186
193
}
187
194
}
195
+ if expectedFiles .Len () != 0 {
196
+ t .Errorf ("Some expected files were not found in directory %q: %s" , path , expectedFiles .UnsortedList ())
197
+ }
188
198
}
0 commit comments