diff --git a/snapshots/overlay/overlay_test.go b/snapshots/overlay/overlay_test.go index 17f555d55..7671b83dc 100644 --- a/snapshots/overlay/overlay_test.go +++ b/snapshots/overlay/overlay_test.go @@ -34,21 +34,49 @@ import ( "github.com/containerd/containerd/snapshots/testsuite" ) -func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) { - snapshotter, err := NewSnapshotter(root) - if err != nil { - return nil, nil, err - } +func newSnapshotterWithOpts(opts ...Opt) testsuite.SnapshotterFunc { + return func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) { + snapshotter, err := NewSnapshotter(root, opts...) + if err != nil { + return nil, nil, err + } - return snapshotter, func() error { return snapshotter.Close() }, nil + return snapshotter, func() error { return snapshotter.Close() }, nil + } } func TestOverlay(t *testing.T) { testutil.RequiresRoot(t) - testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter) + optTestCases := map[string][]Opt{ + "no opt": nil, + // default in init() + "AsynchronousRemove": {AsynchronousRemove}, + } + + for optsName, opts := range optTestCases { + t.Run(optsName, func(t *testing.T) { + newSnapshotter := newSnapshotterWithOpts(opts...) + testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter) + t.Run("TestOverlayMounts", func(t *testing.T) { + testOverlayMounts(t, newSnapshotter) + }) + t.Run("TestOverlayCommit", func(t *testing.T) { + testOverlayCommit(t, newSnapshotter) + }) + t.Run("TestOverlayOverlayMount", func(t *testing.T) { + testOverlayOverlayMount(t, newSnapshotter) + }) + t.Run("TestOverlayOverlayRead", func(t *testing.T) { + testOverlayOverlayRead(t, newSnapshotter) + }) + t.Run("TestOverlayView", func(t *testing.T) { + testOverlayView(t, newSnapshotter) + }) + }) + } } -func TestOverlayMounts(t *testing.T) { +func testOverlayMounts(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) { ctx := context.TODO() root, err := ioutil.TempDir("", "overlay") if err != nil { @@ -82,7 +110,7 @@ func TestOverlayMounts(t *testing.T) { } } -func TestOverlayCommit(t *testing.T) { +func testOverlayCommit(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) { ctx := context.TODO() root, err := ioutil.TempDir("", "overlay") if err != nil { @@ -107,7 +135,7 @@ func TestOverlayCommit(t *testing.T) { } } -func TestOverlayOverlayMount(t *testing.T) { +func testOverlayOverlayMount(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) { ctx := context.TODO() root, err := ioutil.TempDir("", "overlay") if err != nil { @@ -190,7 +218,7 @@ func getParents(ctx context.Context, sn snapshots.Snapshotter, root, key string) return parents } -func TestOverlayOverlayRead(t *testing.T) { +func testOverlayOverlayRead(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) { testutil.RequiresRoot(t) ctx := context.TODO() root, err := ioutil.TempDir("", "overlay") @@ -234,7 +262,7 @@ func TestOverlayOverlayRead(t *testing.T) { } } -func TestOverlayView(t *testing.T) { +func testOverlayView(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) { ctx := context.TODO() root, err := ioutil.TempDir("", "overlay") if err != nil { diff --git a/snapshots/testsuite/testsuite.go b/snapshots/testsuite/testsuite.go index 11ebfdc1d..c5af695f0 100644 --- a/snapshots/testsuite/testsuite.go +++ b/snapshots/testsuite/testsuite.go @@ -38,8 +38,11 @@ import ( is "gotest.tools/assert/cmp" ) +// SnapshotterFunc is used in SnapshotterSuite +type SnapshotterFunc func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) + // SnapshotterSuite runs a test suite on the snapshotter given a factory function. -func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error)) { +func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc) { restoreMask := clearMask() defer restoreMask()