containerd/snapshot/naive/naive_test.go
Stephen J Day 68fd25221d
snapshot: define the snapshot driver interface
We now define the `snapshot.Driver` interface based on earlier work.
Many details of the model are worked out, such as snapshot lifecycle and
parentage of commits against "Active" snapshots.

The impetus of this change is to provide a snapshot POC that does a
complete push/pull workflow. The beginnings of a test suite for snapshot
drivers is included that we can use to verify the assumptions of
drivers. The intent is to port the existing tests over to this test
suite and start scaling contributions and test to the snapshot driver
subsystem.

There are still some details that need to be worked out, such as listing
and metadata access. We can do this activity as we further integrate
with tooling.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-02-02 18:06:02 -08:00

92 lines
2 KiB
Go

package naive
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/docker/containerd"
"github.com/docker/containerd/testutil"
)
func TestSnapshotNaiveBasic(t *testing.T) {
testutil.RequiresRoot(t)
tmpDir, err := ioutil.TempDir("", "test-naive-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
t.Log(tmpDir)
root := filepath.Join(tmpDir, "root")
n, err := NewNaive(root)
if err != nil {
t.Fatal(err)
}
preparing := filepath.Join(tmpDir, "preparing")
if err := os.MkdirAll(preparing, 0777); err != nil {
t.Fatal(err)
}
mounts, err := n.Prepare(preparing, "")
if err != nil {
t.Fatal(err)
}
if err := containerd.MountAll(mounts, preparing); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil {
t.Fatal(err)
}
os.MkdirAll(preparing+"/a/b/c", 0755)
// defer os.Remove(filepath.Join(tmpDir, "foo"))
committed := filepath.Join(n.root, "committed")
if err := n.Commit(committed, preparing); err != nil {
t.Fatal(err)
}
if n.Parent(preparing) != "" {
t.Fatalf("parent of new layer should be empty, got n.Parent(%q) == %q", preparing, n.Parent(preparing))
}
next := filepath.Join(tmpDir, "nextlayer")
if err := os.MkdirAll(next, 0777); err != nil {
t.Fatal(err)
}
mounts, err = n.Prepare(next, committed)
if err != nil {
t.Fatal(err)
}
if err := containerd.MountAll(mounts, next); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(next, "bar"), []byte("bar\n"), 0777); err != nil {
t.Fatal(err)
}
// also, change content of foo to bar
if err := ioutil.WriteFile(filepath.Join(next, "foo"), []byte("bar\n"), 0777); err != nil {
t.Fatal(err)
}
os.RemoveAll(next + "/a/b")
nextCommitted := filepath.Join(n.root, "committed-next")
if err := n.Commit(nextCommitted, next); err != nil {
t.Fatal(err)
}
if n.Parent(nextCommitted) != committed {
t.Fatalf("parent of new layer should be %q, got n.Parent(%q) == %q (%#v)", committed, next, n.Parent(next), n.parents)
}
}