Merge pull request #3932 from AkihiroSuda/ovl-test-opts

overlay: test actual Opts
This commit is contained in:
Michael Crosby 2020-01-07 12:07:07 -05:00 committed by GitHub
commit 0d276ece0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 13 deletions

View File

@ -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 {

View File

@ -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()