Skip to content

Commit a4b423b

Browse files
committed
overlay: test actual Opts
AsynchronousRemove opt was untested while it is specified by default in the plugin init. Signed-off-by: Akihiro Suda <[email protected]>
1 parent b9fad5e commit a4b423b

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

snapshots/overlay/overlay_test.go

+40-12
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,49 @@ import (
3434
"github.com/containerd/containerd/snapshots/testsuite"
3535
)
3636

37-
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
38-
snapshotter, err := NewSnapshotter(root)
39-
if err != nil {
40-
return nil, nil, err
41-
}
37+
func newSnapshotterWithOpts(opts ...Opt) testsuite.SnapshotterFunc {
38+
return func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
39+
snapshotter, err := NewSnapshotter(root, opts...)
40+
if err != nil {
41+
return nil, nil, err
42+
}
4243

43-
return snapshotter, func() error { return snapshotter.Close() }, nil
44+
return snapshotter, func() error { return snapshotter.Close() }, nil
45+
}
4446
}
4547

4648
func TestOverlay(t *testing.T) {
4749
testutil.RequiresRoot(t)
48-
testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter)
50+
optTestCases := map[string][]Opt{
51+
"no opt": nil,
52+
// default in init()
53+
"AsynchronousRemove": {AsynchronousRemove},
54+
}
55+
56+
for optsName, opts := range optTestCases {
57+
t.Run(optsName, func(t *testing.T) {
58+
newSnapshotter := newSnapshotterWithOpts(opts...)
59+
testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter)
60+
t.Run("TestOverlayMounts", func(t *testing.T) {
61+
testOverlayMounts(t, newSnapshotter)
62+
})
63+
t.Run("TestOverlayCommit", func(t *testing.T) {
64+
testOverlayCommit(t, newSnapshotter)
65+
})
66+
t.Run("TestOverlayOverlayMount", func(t *testing.T) {
67+
testOverlayOverlayMount(t, newSnapshotter)
68+
})
69+
t.Run("TestOverlayOverlayRead", func(t *testing.T) {
70+
testOverlayOverlayRead(t, newSnapshotter)
71+
})
72+
t.Run("TestOverlayView", func(t *testing.T) {
73+
testOverlayView(t, newSnapshotter)
74+
})
75+
})
76+
}
4977
}
5078

51-
func TestOverlayMounts(t *testing.T) {
79+
func testOverlayMounts(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
5280
ctx := context.TODO()
5381
root, err := ioutil.TempDir("", "overlay")
5482
if err != nil {
@@ -82,7 +110,7 @@ func TestOverlayMounts(t *testing.T) {
82110
}
83111
}
84112

85-
func TestOverlayCommit(t *testing.T) {
113+
func testOverlayCommit(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
86114
ctx := context.TODO()
87115
root, err := ioutil.TempDir("", "overlay")
88116
if err != nil {
@@ -107,7 +135,7 @@ func TestOverlayCommit(t *testing.T) {
107135
}
108136
}
109137

110-
func TestOverlayOverlayMount(t *testing.T) {
138+
func testOverlayOverlayMount(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
111139
ctx := context.TODO()
112140
root, err := ioutil.TempDir("", "overlay")
113141
if err != nil {
@@ -190,7 +218,7 @@ func getParents(ctx context.Context, sn snapshots.Snapshotter, root, key string)
190218
return parents
191219
}
192220

193-
func TestOverlayOverlayRead(t *testing.T) {
221+
func testOverlayOverlayRead(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
194222
testutil.RequiresRoot(t)
195223
ctx := context.TODO()
196224
root, err := ioutil.TempDir("", "overlay")
@@ -234,7 +262,7 @@ func TestOverlayOverlayRead(t *testing.T) {
234262
}
235263
}
236264

237-
func TestOverlayView(t *testing.T) {
265+
func testOverlayView(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
238266
ctx := context.TODO()
239267
root, err := ioutil.TempDir("", "overlay")
240268
if err != nil {

snapshots/testsuite/testsuite.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ import (
3838
is "gotest.tools/assert/cmp"
3939
)
4040

41+
// SnapshotterFunc is used in SnapshotterSuite
42+
type SnapshotterFunc func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error)
43+
4144
// SnapshotterSuite runs a test suite on the snapshotter given a factory function.
42-
func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error)) {
45+
func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc) {
4346
restoreMask := clearMask()
4447
defer restoreMask()
4548

0 commit comments

Comments
 (0)