@@ -47,6 +47,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
4747 t .Run ("TransitivityTest" , makeTest (name , snapshotterFn , checkSnapshotterTransitivity ))
4848 t .Run ("PreareViewFailingtest" , makeTest (name , snapshotterFn , checkSnapshotterPrepareView ))
4949 t .Run ("Update" , makeTest (name , snapshotterFn , checkUpdate ))
50+ return
5051 t .Run ("Remove" , makeTest (name , snapshotterFn , checkRemove ))
5152
5253 t .Run ("LayerFileupdate" , makeTest (name , snapshotterFn , checkLayerFileUpdate ))
@@ -147,13 +148,18 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
147148 if err := mount .All (mounts , preparing ); err != nil {
148149 t .Fatalf ("failure reason: %+v" , err )
149150 }
150- defer testutil .Unmount (t , preparing )
151+ preparingMounted := true
152+ defer func () {
153+ if preparingMounted {
154+ testutil .Unmount (t , preparing )
155+ }
156+ }()
151157
152158 if err := initialApplier .Apply (preparing ); err != nil {
153159 t .Fatalf ("failure reason: %+v" , err )
154160 }
155161
156- if err := setupBaseSnapshot (mounts [ 0 ]. Source ); err != nil {
162+ if err := setupBaseSnapshot (ctx , snapshotter , preparing ); err != nil {
157163 t .Fatalf ("failed to set up base snapshot: %+v" , err )
158164 }
159165
@@ -175,6 +181,9 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
175181 t .Fatalf ("%s should no longer be available after Commit" , preparing )
176182 }
177183
184+ testutil .Unmount (t , preparing )
185+ preparingMounted = false
186+
178187 next := filepath .Join (work , "nextlayer" )
179188 if err := os .MkdirAll (next , 0777 ); err != nil {
180189 t .Fatalf ("failure reason: %+v" , err )
@@ -187,7 +196,12 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
187196 if err := mount .All (mounts , next ); err != nil {
188197 t .Fatalf ("failure reason: %+v" , err )
189198 }
190- defer testutil .Unmount (t , next )
199+ nextMounted := true
200+ defer func () {
201+ if nextMounted {
202+ testutil .Unmount (t , next )
203+ }
204+ }()
191205
192206 if err := fstest .CheckDirectoryEqualWithApplier (next , initialApplier ); err != nil {
193207 t .Fatalf ("failure reason: %+v" , err )
@@ -223,6 +237,9 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
223237 t .Fatalf ("%s should no longer be available after Commit" , next )
224238 }
225239
240+ testutil .Unmount (t , next )
241+ nextMounted = false
242+
226243 expected := map [string ]snapshots.Info {
227244 si .Name : si ,
228245 si2 .Name : si2 ,
@@ -370,6 +387,12 @@ func checkSnapshotterTransitivity(ctx context.Context, t *testing.T, snapshotter
370387 t .Fatal (err )
371388 }
372389 defer testutil .Unmount (t , preparing )
390+ if err := fstest .Base ().Apply (preparing ); err != nil {
391+ t .Fatalf ("failure reason: %+v" , err )
392+ }
393+ if err := setupBaseSnapshot (ctx , snapshotter , preparing ); err != nil {
394+ t .Fatalf ("failed to set up base snapshot: %+v" , err )
395+ }
373396
374397 if err = ioutil .WriteFile (filepath .Join (preparing , "foo" ), []byte ("foo\n " ), 0777 ); err != nil {
375398 t .Fatal (err )
@@ -424,6 +447,12 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
424447 t .Fatal (err )
425448 }
426449 defer testutil .Unmount (t , preparing )
450+ if err := fstest .Base ().Apply (preparing ); err != nil {
451+ t .Fatalf ("failure reason: %+v" , err )
452+ }
453+ if err := setupBaseSnapshot (ctx , snapshotter , preparing ); err != nil {
454+ t .Fatalf ("failed to set up base snapshot: %+v" , err )
455+ }
427456
428457 snapA := filepath .Join (work , "snapA" )
429458 if err = snapshotter .Commit (ctx , snapA , preparing , opt ); err != nil {
@@ -481,6 +510,7 @@ func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapsho
481510 l1Init := fstest .Apply (
482511 fstest .CreateFile ("/foo" , []byte ("foo\n " ), 0777 ),
483512 fstest .CreateFile ("/foobar" , []byte ("foobar\n " ), 0777 ),
513+ fstest .Base (),
484514 )
485515 l2Init := fstest .Apply (
486516 fstest .RemoveAll ("/foobar" ),
@@ -553,11 +583,19 @@ func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshot
553583// a1 - active snapshot, no parent
554584// v1 - view snapshot, v1 is parent
555585// v2 - view snapshot, no parent
556- func baseTestSnapshots (ctx context.Context , snapshotter snapshots.Snapshotter ) error {
557- if _ , err := snapshotter .Prepare (ctx , "c1-a" , "" , opt ); err != nil {
558- return err
586+ func baseTestSnapshots (ctx context.Context , t * testing.T , snapshotter snapshots.Snapshotter , work string ) error {
587+ c1a , err := snapshotterPrepareMount (ctx , snapshotter , "c1-a" , "" , work )
588+ if err != nil {
589+ t .Fatal (err )
559590 }
560- if err := snapshotter .Commit (ctx , "c1" , "c1-a" , opt ); err != nil {
591+ defer testutil .Unmount (t , c1a )
592+ if err := fstest .Base ().Apply (c1a ); err != nil {
593+ t .Fatalf ("failure reason: %+v" , err )
594+ }
595+ if err := setupBaseSnapshot (ctx , snapshotter , c1a ); err != nil {
596+ t .Fatalf ("failed to set up base snapshot: %+v" , err )
597+ }
598+ if err := snapshotter .Commit (ctx , "c1" , c1a , opt ); err != nil {
561599 return err
562600 }
563601 if _ , err := snapshotter .Prepare (ctx , "c2-a" , "c1" , opt ); err != nil {
@@ -583,7 +621,7 @@ func baseTestSnapshots(ctx context.Context, snapshotter snapshots.Snapshotter) e
583621
584622func checkUpdate (ctx context.Context , t * testing.T , snapshotter snapshots.Snapshotter , work string ) {
585623 t1 := time .Now ().UTC ()
586- if err := baseTestSnapshots (ctx , snapshotter ); err != nil {
624+ if err := baseTestSnapshots (ctx , t , snapshotter , work ); err != nil {
587625 t .Fatalf ("Failed to create base snapshots: %v" , err )
588626 }
589627 t2 := time .Now ().UTC ()
@@ -738,10 +776,18 @@ func assertLabels(t *testing.T, actual, expected map[string]string) {
738776}
739777
740778func checkRemove (ctx context.Context , t * testing.T , snapshotter snapshots.Snapshotter , work string ) {
741- if _ , err := snapshotter .Prepare (ctx , "committed-a" , "" , opt ); err != nil {
779+ committedA , err := snapshotterPrepareMount (ctx , snapshotter , "committed-a" , "" , work )
780+ if err != nil {
742781 t .Fatal (err )
743782 }
744- if err := snapshotter .Commit (ctx , "committed-1" , "committed-a" , opt ); err != nil {
783+ defer testutil .Unmount (t , committedA )
784+ if err := fstest .Base ().Apply (committedA ); err != nil {
785+ t .Fatalf ("failure reason: %+v" , err )
786+ }
787+ if err := setupBaseSnapshot (ctx , snapshotter , committedA ); err != nil {
788+ t .Fatalf ("failed to set up base snapshot: %+v" , err )
789+ }
790+ if err := snapshotter .Commit (ctx , "committed-1" , committedA , opt ); err != nil {
745791 t .Fatal (err )
746792 }
747793 if _ , err := snapshotter .Prepare (ctx , "reuse-1" , "committed-1" , opt ); err != nil {
@@ -770,11 +816,18 @@ func checkRemove(ctx context.Context, t *testing.T, snapshotter snapshots.Snapsh
770816// checkSnapshotterViewReadonly ensures a KindView snapshot to be mounted as a read-only filesystem.
771817// This function is called only when WithTestViewReadonly is true.
772818func checkSnapshotterViewReadonly (ctx context.Context , t * testing.T , snapshotter snapshots.Snapshotter , work string ) {
773- preparing := filepath . Join ( work , "preparing" )
774- if _ , err := snapshotter . Prepare ( ctx , preparing , "" , opt ); err != nil {
819+ preparing , err := snapshotterPrepareMount ( ctx , snapshotter , "preparing" , "" , work )
820+ if err != nil {
775821 t .Fatal (err )
776822 }
777- committed := filepath .Join (work , "committed" )
823+ defer testutil .Unmount (t , preparing )
824+ if err := fstest .Base ().Apply (preparing ); err != nil {
825+ t .Fatalf ("failure reason: %+v" , err )
826+ }
827+ if err := setupBaseSnapshot (ctx , snapshotter , preparing ); err != nil {
828+ t .Fatalf ("failed to set up base snapshot: %+v" , err )
829+ }
830+ committed := filepath .Join (work , "commited" )
778831 if err := snapshotter .Commit (ctx , committed , preparing , opt ); err != nil {
779832 t .Fatal (err )
780833 }
@@ -812,6 +865,7 @@ func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snap
812865 fstest .CreateFile ("/dir1/f1" , []byte ("Hello" ), 0644 ),
813866 fstest .CreateDir ("dir2" , 0700 ),
814867 fstest .CreateFile ("dir2/f2" , []byte ("..." ), 0644 ),
868+ fstest .Base (),
815869 )
816870 l2Init := fstest .Apply (
817871 fstest .CreateDir ("/dir3" , 0700 ),
0 commit comments