Skip to content

Commit 313cebc

Browse files
authored
Merge pull request containerd#1473 from kunalkushwaha/snapshot-testcases
Two Snapshot testcases added
2 parents 52fbc5f + b6fb234 commit 313cebc

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

snapshot/testsuite/testsuite.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
3535
t.Run("RemoveDirectoryInLowerLayer", makeTest(name, snapshotterFn, checkRemoveDirectoryInLowerLayer))
3636
t.Run("Chown", makeTest(name, snapshotterFn, checkChown))
3737
t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit))
38-
38+
t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot))
39+
t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot))
3940
// Rename test still fails on some kernels with overlay
4041
//t.Run("Rename", makeTest(name, snapshotterFn, checkRename))
4142

@@ -437,6 +438,76 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
437438

438439
}
439440

441+
// Deletion of files/folder of base layer in new layer, On Commit, those files should not be visible.
442+
func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
443+
444+
l1Init := fstest.Apply(
445+
fstest.CreateFile("/foo", []byte("foo\n"), 0777),
446+
fstest.CreateFile("/foobar", []byte("foobar\n"), 0777),
447+
)
448+
l2Init := fstest.Apply(
449+
fstest.RemoveAll("/foobar"),
450+
)
451+
l3Init := fstest.Apply()
452+
453+
if err := checkSnapshots(ctx, snapshotter, work, l1Init, l2Init, l3Init); err != nil {
454+
t.Fatalf("Check snapshots failed: %+v", err)
455+
}
456+
457+
}
458+
459+
//Create three layers. Deleting intermediate layer must fail.
460+
func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
461+
462+
base, err := snapshotterPrepareMount(ctx, snapshotter, "base", "", work)
463+
if err != nil {
464+
t.Fatal(err)
465+
}
466+
defer testutil.Unmount(t, base)
467+
468+
committedBase := filepath.Join(work, "committed-base")
469+
if err = snapshotter.Commit(ctx, committedBase, base); err != nil {
470+
t.Fatal(err)
471+
}
472+
473+
// Create intermediate layer
474+
intermediate := filepath.Join(work, "intermediate")
475+
if _, err = snapshotter.Prepare(ctx, intermediate, committedBase); err != nil {
476+
t.Fatal(err)
477+
}
478+
479+
committedInter := filepath.Join(work, "committed-inter")
480+
if err = snapshotter.Commit(ctx, committedInter, intermediate); err != nil {
481+
t.Fatal(err)
482+
}
483+
484+
// Create top layer
485+
topLayer := filepath.Join(work, "toplayer")
486+
if _, err = snapshotter.Prepare(ctx, topLayer, committedInter); err != nil {
487+
t.Fatal(err)
488+
}
489+
490+
// Deletion of intermediate layer must fail.
491+
err = snapshotter.Remove(ctx, committedInter)
492+
if err == nil {
493+
t.Fatal("intermediate layer removal should fail.")
494+
}
495+
496+
//Removal from toplayer to base should not fail.
497+
err = snapshotter.Remove(ctx, topLayer)
498+
if err != nil {
499+
t.Fatal(err)
500+
}
501+
err = snapshotter.Remove(ctx, committedInter)
502+
if err != nil {
503+
t.Fatal(err)
504+
}
505+
err = snapshotter.Remove(ctx, committedBase)
506+
if err != nil {
507+
t.Fatal(err)
508+
}
509+
}
510+
440511
// baseTestSnapshots creates a base set of snapshots for tests, each snapshot is empty
441512
// Tests snapshots:
442513
// c1 - committed snapshot, no parent

0 commit comments

Comments
 (0)