Merge pull request #3932 from AkihiroSuda/ovl-test-opts
overlay: test actual Opts
This commit is contained in:
commit
0d276ece0e
@ -34,21 +34,49 @@ import (
|
|||||||
"github.com/containerd/containerd/snapshots/testsuite"
|
"github.com/containerd/containerd/snapshots/testsuite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
func newSnapshotterWithOpts(opts ...Opt) testsuite.SnapshotterFunc {
|
||||||
snapshotter, err := NewSnapshotter(root)
|
return func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||||
if err != nil {
|
snapshotter, err := NewSnapshotter(root, opts...)
|
||||||
return nil, nil, err
|
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) {
|
func TestOverlay(t *testing.T) {
|
||||||
testutil.RequiresRoot(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()
|
ctx := context.TODO()
|
||||||
root, err := ioutil.TempDir("", "overlay")
|
root, err := ioutil.TempDir("", "overlay")
|
||||||
if err != nil {
|
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()
|
ctx := context.TODO()
|
||||||
root, err := ioutil.TempDir("", "overlay")
|
root, err := ioutil.TempDir("", "overlay")
|
||||||
if err != nil {
|
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()
|
ctx := context.TODO()
|
||||||
root, err := ioutil.TempDir("", "overlay")
|
root, err := ioutil.TempDir("", "overlay")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -190,7 +218,7 @@ func getParents(ctx context.Context, sn snapshots.Snapshotter, root, key string)
|
|||||||
return parents
|
return parents
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverlayOverlayRead(t *testing.T) {
|
func testOverlayOverlayRead(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
|
||||||
testutil.RequiresRoot(t)
|
testutil.RequiresRoot(t)
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
root, err := ioutil.TempDir("", "overlay")
|
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()
|
ctx := context.TODO()
|
||||||
root, err := ioutil.TempDir("", "overlay")
|
root, err := ioutil.TempDir("", "overlay")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -38,8 +38,11 @@ import (
|
|||||||
is "gotest.tools/assert/cmp"
|
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.
|
// 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()
|
restoreMask := clearMask()
|
||||||
defer restoreMask()
|
defer restoreMask()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user