containerd/metadata/snapshot_test.go
Jess Valarezo 9885edfc44 rename snapshot->snapshots pkg
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-11-29 14:55:02 -08:00

50 lines
1.2 KiB
Go

package metadata
import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/boltdb/bolt"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/naive"
"github.com/containerd/containerd/snapshots/testsuite"
"github.com/containerd/containerd/testutil"
)
func newTestSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, 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 := NewDB(db, nil, map[string]snapshots.Snapshotter{"naive": snapshotter}).Snapshotter("naive")
return sn, func() error {
if err := sn.Close(); err != nil {
return err
}
return db.Close()
}, nil
}
func TestMetadata(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("snapshotter not implemented on windows")
}
// Snapshot tests require mounting, still requires root
testutil.RequiresRoot(t)
testsuite.SnapshotterSuite(t, "Metadata", newTestSnapshotter)
}