From da5c72c33562964125a50ea0caf9121ccec60361 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 25 Jul 2017 10:47:45 -0700 Subject: [PATCH 1/2] Run snapshot test suite for metadata and client The snapshot test suite is designed to run against the snapshotter interface, run the test suite for metadata and client implementations of the snapshotter interface. Signed-off-by: Derek McGowan --- metadata/snapshot_test.go | 42 +++++++++++++++++++++++++++++++++ snapshot/testsuite/testsuite.go | 2 ++ snapshot_test.go | 29 +++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 metadata/snapshot_test.go create mode 100644 snapshot_test.go diff --git a/metadata/snapshot_test.go b/metadata/snapshot_test.go new file mode 100644 index 000000000..573d3b83d --- /dev/null +++ b/metadata/snapshot_test.go @@ -0,0 +1,42 @@ +package metadata + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/boltdb/bolt" + "github.com/containerd/containerd/snapshot" + "github.com/containerd/containerd/snapshot/naive" + "github.com/containerd/containerd/snapshot/testsuite" + "github.com/containerd/containerd/testutil" +) + +func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func(), error) { + naiveRoot := filepath.Join(root, "naive") + if err := os.Mkdir(naiveRoot, 0770); err != nil { + return nil, nil, err + } + snapshotter, err := naive.NewSnapshotter(naiveRoot) + if err != nil { + return nil, nil, err + } + + db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil) + if err != nil { + return nil, nil, err + } + + sn := NewSnapshotter(db, "naive", snapshotter) + + return sn, func() { + db.Close() + }, nil +} + +func TestMetadata(t *testing.T) { + // Snapshot tests require mounting, still requires root + testutil.RequiresRoot(t) + testsuite.SnapshotterSuite(t, "Metadata", newSnapshotter) +} diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index 3eddf2dcc..2f85c5a6d 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -10,6 +10,7 @@ import ( "github.com/containerd/containerd/fs/fstest" "github.com/containerd/containerd/mount" + "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/testutil" "github.com/stretchr/testify/assert" @@ -27,6 +28,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context. func makeTest(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshot.Snapshotter, func(), error), fn func(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) { return func(t *testing.T) { ctx := context.Background() + ctx = namespaces.WithNamespace(ctx, "testsuite") restoreMask := clearMask() defer restoreMask() // Make two directories: a snapshotter root and a play area for the tests: diff --git a/snapshot_test.go b/snapshot_test.go new file mode 100644 index 000000000..f3c2be74c --- /dev/null +++ b/snapshot_test.go @@ -0,0 +1,29 @@ +package containerd + +import ( + "context" + "testing" + + "github.com/containerd/containerd/snapshot" + "github.com/containerd/containerd/snapshot/testsuite" +) + +func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func(), error) { + client, err := New(address) + if err != nil { + return nil, nil, err + } + + sn := client.SnapshotService("") + + return sn, func() { + client.Close() + }, nil +} + +func TestSnapshotterClient(t *testing.T) { + if testing.Short() { + t.Skip() + } + testsuite.SnapshotterSuite(t, "SnapshotterClient", newSnapshotter) +} From 585f7d649484f998bbd50aeb97a58a547ca8a870 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 27 Jul 2017 15:42:34 -0700 Subject: [PATCH 2/2] Skip test on windows Signed-off-by: Derek McGowan --- snapshot_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/snapshot_test.go b/snapshot_test.go index f3c2be74c..d52bc79cc 100644 --- a/snapshot_test.go +++ b/snapshot_test.go @@ -2,6 +2,7 @@ package containerd import ( "context" + "runtime" "testing" "github.com/containerd/containerd/snapshot" @@ -25,5 +26,8 @@ func TestSnapshotterClient(t *testing.T) { if testing.Short() { t.Skip() } + if runtime.GOOS == "windows" { + t.Skip("snapshots not yet supported on Windows") + } testsuite.SnapshotterSuite(t, "SnapshotterClient", newSnapshotter) }