From 8442e4bbe33faab7365cf4aa59e4bc30a986dff0 Mon Sep 17 00:00:00 2001 From: Kunal Kushwaha Date: Mon, 11 Sep 2017 11:15:50 +0900 Subject: [PATCH] Testcase added for Moving files in snapshot layers Movement of files/folder from base layer to folder in new layer should be allowed Signed-off-by: Kunal Kushwaha --- snapshot/testsuite/testsuite.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index 67e35b5a0..16f33f210 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -37,6 +37,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context. t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit)) t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot)) t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot)) + t.Run("MoveFileFromLowerLayer", makeTest(name, snapshotterFn, checkFileFromLowerLayer)) // Rename test still fails on some kernels with overlay //t.Run("Rename", makeTest(name, snapshotterFn, checkRename)) @@ -761,3 +762,25 @@ func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter assert.NoError(t, snapshotter.Remove(ctx, view)) assert.NoError(t, snapshotter.Remove(ctx, committed)) } + +// Move files from base layer to new location in intermediate layer. +// Verify if the file at source is deleted and copied to new location. +func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) { + l1Init := fstest.Apply( + fstest.CreateDir("/dir1", 0700), + fstest.CreateFile("/dir1/f1", []byte("Hello"), 0644), + fstest.CreateDir("dir2", 0700), + fstest.CreateFile("dir2/f2", []byte("..."), 0644), + ) + l2Init := fstest.Apply( + fstest.CreateDir("/dir3", 0700), + fstest.CreateFile("/dir3/f1", []byte("Hello"), 0644), + fstest.RemoveAll("/dir1"), + fstest.Link("dir2/f2", "dir3/f2"), + fstest.RemoveAll("dir2/f2"), + ) + + if err := checkSnapshots(ctx, snapshotter, work, l1Init, l2Init); err != nil { + t.Fatalf("Check snapshots failed: %+v", err) + } +}