diff --git a/integration/client/snapshot_test.go b/integration/client/snapshot_test.go index d5eed0a5e..1aca97147 100644 --- a/integration/client/snapshot_test.go +++ b/integration/client/snapshot_test.go @@ -47,5 +47,5 @@ func TestSnapshotterClient(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("snapshots not yet supported on Windows") } - testsuite.SnapshotterSuite(t, "SnapshotterClient", newSnapshotter) + testsuite.SnapshotterSuite(t, DefaultSnapshotter, newSnapshotter) } diff --git a/snapshots/overlay/overlay_test.go b/snapshots/overlay/overlay_test.go index 279613935..13493c45e 100644 --- a/snapshots/overlay/overlay_test.go +++ b/snapshots/overlay/overlay_test.go @@ -57,7 +57,7 @@ func TestOverlay(t *testing.T) { for optsName, opts := range optTestCases { t.Run(optsName, func(t *testing.T) { newSnapshotter := newSnapshotterWithOpts(opts...) - testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter) + testsuite.SnapshotterSuite(t, "overlayfs", newSnapshotter) t.Run("TestOverlayMounts", func(t *testing.T) { testOverlayMounts(t, newSnapshotter) }) diff --git a/snapshots/testsuite/issues.go b/snapshots/testsuite/issues.go index 6a5fe49a0..eea87767e 100644 --- a/snapshots/testsuite/issues.go +++ b/snapshots/testsuite/issues.go @@ -114,23 +114,33 @@ func checkChown(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, wor // checkRename // https://github.com/docker/docker/issues/25409 -func checkRename(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) { - t.Skip("rename test still fails on some kernels with overlay") - l1Init := fstest.Apply( - fstest.CreateDir("/dir1", 0700), - fstest.CreateDir("/somefiles", 0700), - fstest.CreateFile("/somefiles/f1", []byte("was here first!"), 0644), - fstest.CreateFile("/somefiles/f2", []byte("nothing interesting"), 0644), - ) - l2Init := fstest.Apply( - fstest.Rename("/dir1", "/dir2"), - fstest.CreateFile("/somefiles/f1-overwrite", []byte("new content 1"), 0644), - fstest.Rename("/somefiles/f1-overwrite", "/somefiles/f1"), - fstest.Rename("/somefiles/f2", "/somefiles/f3"), - ) +func checkRename(ss string) func(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) { + return func(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) { + l1Init := fstest.Apply( + fstest.CreateDir("/dir1", 0700), + fstest.CreateDir("/somefiles", 0700), + fstest.CreateFile("/somefiles/f1", []byte("was here first!"), 0644), + fstest.CreateFile("/somefiles/f2", []byte("nothing interesting"), 0644), + ) - if err := checkSnapshots(ctx, sn, work, l1Init, l2Init); err != nil { - t.Fatalf("Check snapshots failed: %+v", err) + var applier []fstest.Applier + if ss != "overlayfs" { + // With neither OVERLAY_FS_REDIRECT_DIR nor redirect_dir, + // renaming the directory on the lower directory doesn't work on overlayfs. + // https://github.com/torvalds/linux/blob/v5.18/Documentation/filesystems/overlayfs.rst#renaming-directories + applier = append(applier, fstest.Rename("/dir1", "/dir2")) + } + applier = append( + applier, + fstest.CreateFile("/somefiles/f1-overwrite", []byte("new content 1"), 0644), + fstest.Rename("/somefiles/f1-overwrite", "/somefiles/f1"), + fstest.Rename("/somefiles/f2", "/somefiles/f3"), + ) + l2Init := fstest.Apply(applier...) + + if err := checkSnapshots(ctx, sn, work, l1Init, l2Init); err != nil { + t.Fatalf("Check snapshots failed: %+v", err) + } } } diff --git a/snapshots/testsuite/testsuite.go b/snapshots/testsuite/testsuite.go index d62c41496..cf793d1cd 100644 --- a/snapshots/testsuite/testsuite.go +++ b/snapshots/testsuite/testsuite.go @@ -62,7 +62,6 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc) t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot)) t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot)) t.Run("MoveFileFromLowerLayer", makeTest(name, snapshotterFn, checkFileFromLowerLayer)) - t.Run("Rename", makeTest(name, snapshotterFn, checkRename)) t.Run("ViewReadonly", makeTest(name, snapshotterFn, checkSnapshotterViewReadonly)) @@ -70,10 +69,16 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc) t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice)) t.Run("RootPermission", makeTest(name, snapshotterFn, checkRootPermission)) + // Different snapshotters behave slightly differently in the tests below. + t.Run("Rename", makeTest(name, snapshotterFn, checkRename(name))) t.Run("128LayersMount", makeTest(name, snapshotterFn, check128LayersMount(name))) } -func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string)) func(t *testing.T) { +func makeTest( + snapshotter string, + snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), + fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string), +) func(t *testing.T) { return func(t *testing.T) { t.Parallel() @@ -85,7 +90,7 @@ func makeTest(name string, snapshotterFn func(ctx context.Context, root string) // work/ -> passed to test functions // root/ -> passed to snapshotter // - tmpDir, err := os.MkdirTemp("", "snapshot-suite-"+name+"-") + tmpDir, err := os.MkdirTemp("", "snapshot-suite-"+snapshotter+"-") if err != nil { t.Fatal(err) }