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 <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-07-25 10:47:45 -07:00
parent 1251413a96
commit da5c72c335
3 changed files with 73 additions and 0 deletions

42
metadata/snapshot_test.go Normal file
View File

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

View File

@ -10,6 +10,7 @@ import (
"github.com/containerd/containerd/fs/fstest" "github.com/containerd/containerd/fs/fstest"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/stretchr/testify/assert" "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) { 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) { return func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
ctx = namespaces.WithNamespace(ctx, "testsuite")
restoreMask := clearMask() restoreMask := clearMask()
defer restoreMask() defer restoreMask()
// Make two directories: a snapshotter root and a play area for the tests: // Make two directories: a snapshotter root and a play area for the tests:

29
snapshot_test.go Normal file
View File

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