Merge pull request #1473 from kunalkushwaha/snapshot-testcases

Two Snapshot testcases added
This commit is contained in:
Phil Estes 2017-09-11 14:24:44 -04:00 committed by GitHub
commit 313cebc578

View File

@ -35,7 +35,8 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
t.Run("RemoveDirectoryInLowerLayer", makeTest(name, snapshotterFn, checkRemoveDirectoryInLowerLayer)) t.Run("RemoveDirectoryInLowerLayer", makeTest(name, snapshotterFn, checkRemoveDirectoryInLowerLayer))
t.Run("Chown", makeTest(name, snapshotterFn, checkChown)) t.Run("Chown", makeTest(name, snapshotterFn, checkChown))
t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit)) t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit))
t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot))
t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot))
// Rename test still fails on some kernels with overlay // Rename test still fails on some kernels with overlay
//t.Run("Rename", makeTest(name, snapshotterFn, checkRename)) //t.Run("Rename", makeTest(name, snapshotterFn, checkRename))
@ -437,6 +438,76 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
} }
// Deletion of files/folder of base layer in new layer, On Commit, those files should not be visible.
func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
l1Init := fstest.Apply(
fstest.CreateFile("/foo", []byte("foo\n"), 0777),
fstest.CreateFile("/foobar", []byte("foobar\n"), 0777),
)
l2Init := fstest.Apply(
fstest.RemoveAll("/foobar"),
)
l3Init := fstest.Apply()
if err := checkSnapshots(ctx, snapshotter, work, l1Init, l2Init, l3Init); err != nil {
t.Fatalf("Check snapshots failed: %+v", err)
}
}
//Create three layers. Deleting intermediate layer must fail.
func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
base, err := snapshotterPrepareMount(ctx, snapshotter, "base", "", work)
if err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, base)
committedBase := filepath.Join(work, "committed-base")
if err = snapshotter.Commit(ctx, committedBase, base); err != nil {
t.Fatal(err)
}
// Create intermediate layer
intermediate := filepath.Join(work, "intermediate")
if _, err = snapshotter.Prepare(ctx, intermediate, committedBase); err != nil {
t.Fatal(err)
}
committedInter := filepath.Join(work, "committed-inter")
if err = snapshotter.Commit(ctx, committedInter, intermediate); err != nil {
t.Fatal(err)
}
// Create top layer
topLayer := filepath.Join(work, "toplayer")
if _, err = snapshotter.Prepare(ctx, topLayer, committedInter); err != nil {
t.Fatal(err)
}
// Deletion of intermediate layer must fail.
err = snapshotter.Remove(ctx, committedInter)
if err == nil {
t.Fatal("intermediate layer removal should fail.")
}
//Removal from toplayer to base should not fail.
err = snapshotter.Remove(ctx, topLayer)
if err != nil {
t.Fatal(err)
}
err = snapshotter.Remove(ctx, committedInter)
if err != nil {
t.Fatal(err)
}
err = snapshotter.Remove(ctx, committedBase)
if err != nil {
t.Fatal(err)
}
}
// baseTestSnapshots creates a base set of snapshots for tests, each snapshot is empty // baseTestSnapshots creates a base set of snapshots for tests, each snapshot is empty
// Tests snapshots: // Tests snapshots:
// c1 - committed snapshot, no parent // c1 - committed snapshot, no parent