@@ -116,7 +116,7 @@ func TestExamineFiles(t *testing.T) {
116
116
loadMockSnap (t , "mock-snap-1" ),
117
117
loadMockSnap (t , "mock-snap-2" ),
118
118
)
119
- obsolete , used := examineFiles (tests , set {
119
+ obsolete , used , isDirty := examineFiles (tests , set {
120
120
dir1 + "TestSomething_my_test_1.snap" : struct {}{},
121
121
dir2 + "TestAnotherThing_my_simple_test_1.snap" : struct {}{},
122
122
}, "" , false )
@@ -142,6 +142,7 @@ func TestExamineFiles(t *testing.T) {
142
142
143
143
test .Equal (t , obsoleteExpected , obsolete )
144
144
test .Equal (t , usedExpected , used )
145
+ test .True (t , isDirty )
145
146
})
146
147
147
148
t .Run ("should remove outdated files" , func (t * testing.T ) {
@@ -187,10 +188,11 @@ func TestExamineSnaps(t *testing.T) {
187
188
filepath .FromSlash (dir2 + "/test2.snap" ),
188
189
}
189
190
190
- obsolete , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
191
+ obsolete , isDirty , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
191
192
192
193
test .Equal (t , []string {}, obsolete )
193
194
test .NoError (t , err )
195
+ test .False (t , isDirty )
194
196
})
195
197
196
198
t .Run ("should report two obsolete snapshots and not change content" , func (t * testing.T ) {
@@ -208,7 +210,7 @@ func TestExamineSnaps(t *testing.T) {
208
210
// Removing the test entirely
209
211
delete (tests [used [1 ]], "TestDir2_2/TestSimple" )
210
212
211
- obsolete , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
213
+ obsolete , isDirty , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
212
214
content1 := test .GetFileContent (t , used [0 ])
213
215
content2 := test .GetFileContent (t , used [1 ])
214
216
@@ -218,6 +220,7 @@ func TestExamineSnaps(t *testing.T) {
218
220
// Content of snaps is not changed
219
221
test .Equal (t , mockSnap1 , []byte (content1 ))
220
222
test .Equal (t , mockSnap2 , []byte (content2 ))
223
+ test .True (t , isDirty )
221
224
})
222
225
223
226
t .Run ("should update the obsolete snap files" , func (t * testing.T ) {
@@ -236,7 +239,7 @@ func TestExamineSnaps(t *testing.T) {
236
239
delete (tests [used [0 ]], "TestDir1_3/TestSimple" )
237
240
delete (tests [used [1 ]], "TestDir2_1/TestSimple" )
238
241
239
- obsolete , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
242
+ obsolete , isDirty , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
240
243
content1 := test .GetFileContent (t , used [0 ])
241
244
content2 := test .GetFileContent (t , used [1 ])
242
245
@@ -276,10 +279,11 @@ string hello world 2 2 1
276
279
// Content of snaps is not changed
277
280
test .Equal (t , expected1 , content1 )
278
281
test .Equal (t , expected2 , content2 )
282
+ test .True (t , isDirty )
279
283
})
280
284
281
285
t .Run ("should sort all tests" , func (t * testing.T ) {
282
- shouldUpdate , sort := false , true
286
+ shouldUpdate , sort := true , true
283
287
mockSnap1 := loadMockSnap (t , "mock-snap-sort-1" )
284
288
mockSnap2 := loadMockSnap (t , "mock-snap-sort-2" )
285
289
expectedMockSnap1 := loadMockSnap (t , "mock-snap-sort-1-sorted" )
@@ -294,7 +298,7 @@ string hello world 2 2 1
294
298
filepath .FromSlash (dir2 + "/test2.snap" ),
295
299
}
296
300
297
- obsolete , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
301
+ obsolete , isDirty , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
298
302
299
303
test .NoError (t , err )
300
304
test .Equal (t , 0 , len (obsolete ))
@@ -304,6 +308,7 @@ string hello world 2 2 1
304
308
305
309
test .Equal (t , string (expectedMockSnap1 ), content1 )
306
310
test .Equal (t , string (expectedMockSnap2 ), content2 )
311
+ test .True (t , isDirty )
307
312
})
308
313
309
314
t .Run (
@@ -326,7 +331,7 @@ string hello world 2 2 1
326
331
delete (tests [used [0 ]], "TestDir1_3/TestSimple" )
327
332
delete (tests [used [1 ]], "TestDir2_1/TestSimple" )
328
333
329
- obsolete , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
334
+ obsolete , isDirty , err := examineSnaps (tests , used , "" , 1 , shouldUpdate , sort )
330
335
331
336
test .NoError (t , err )
332
337
test .Equal (t , []string {
@@ -344,6 +349,7 @@ string hello world 2 2 1
344
349
345
350
test .Equal (t , string (mockSnap1 ), content1 )
346
351
test .Equal (t , string (mockSnap2 ), content2 )
352
+ test .True (t , isDirty )
347
353
},
348
354
)
349
355
}
0 commit comments