Merge pull request #1230 from dmcgowan/snapshot-client-testsuite

snapshot: run test suite for metadata and client implementations
This commit is contained in:
Stephen Day 2017-07-27 15:49:17 -07:00 committed by GitHub
commit 1679727648
3 changed files with 77 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:

33
snapshot_test.go Normal file
View File

@ -0,0 +1,33 @@
package containerd
import (
"context"
"runtime"
"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()
}
if runtime.GOOS == "windows" {
t.Skip("snapshots not yet supported on Windows")
}
testsuite.SnapshotterSuite(t, "SnapshotterClient", newSnapshotter)
}