Testcase for multiple Prepare/View on same key.

Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
This commit is contained in:
Kunal Kushwaha 2017-03-03 16:18:35 +09:00
parent 27a99400e8
commit 8f13b160b1

View file

@ -22,7 +22,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(root string)
t.Run("StatActive", makeTest(t, name, snapshotterFn, checkSnapshotterStatActive)) t.Run("StatActive", makeTest(t, name, snapshotterFn, checkSnapshotterStatActive))
t.Run("StatComitted", makeTest(t, name, snapshotterFn, checkSnapshotterStatCommitted)) t.Run("StatComitted", makeTest(t, name, snapshotterFn, checkSnapshotterStatCommitted))
t.Run("TransitivityTest", makeTest(t, name, snapshotterFn, checkSnapshotterTransitivity)) t.Run("TransitivityTest", makeTest(t, name, snapshotterFn, checkSnapshotterTransitivity))
t.Run("PreareViewFailingtest", makeTest(t, name, snapshotterFn, checkSnapshotterPrepareView))
} }
func makeTest(t *testing.T, name string, snapshotterFn func(root string) (snapshot.Snapshotter, func(), error), fn func(t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) { func makeTest(t *testing.T, name string, snapshotterFn func(root string) (snapshot.Snapshotter, func(), error), fn func(t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) {
@ -342,3 +342,66 @@ func checkSnapshotterTransitivity(t *testing.T, snapshotter snapshot.Snapshotter
assert.Equal(t, "", siParentB.Parent) assert.Equal(t, "", siParentB.Parent)
} }
// Creating two layers with Prepare or View with same key must fail.
func checkSnapshotterPrepareView(t *testing.T, snapshotter snapshot.Snapshotter, work string) {
ctx := context.TODO()
preparing, err := snapshotterPrepareMount(ctx, snapshotter, "preparing", "", work)
if err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, preparing)
snapA := filepath.Join(work, "snapA")
if err = snapshotter.Commit(ctx, snapA, preparing); err != nil {
t.Fatal(err)
}
// Prepare & View with same key
newLayer := filepath.Join(work, "newlayer")
if err = os.MkdirAll(preparing, 0777); err != nil {
t.Fatal(err)
}
// Prepare & View with same key
_, err = snapshotter.Prepare(ctx, newLayer, snapA)
if err != nil {
t.Fatal(err)
}
_, err = snapshotter.View(ctx, newLayer, snapA)
//must be err != nil
assert.NotNil(t, err)
// Two Prepare with same key
prepLayer := filepath.Join(work, "prepLayer")
if err = os.MkdirAll(preparing, 0777); err != nil {
t.Fatal(err)
}
_, err = snapshotter.Prepare(ctx, prepLayer, snapA)
if err != nil {
t.Fatal(err)
}
_, err = snapshotter.Prepare(ctx, prepLayer, snapA)
//must be err != nil
assert.NotNil(t, err)
// Two View with same key
viewLayer := filepath.Join(work, "viewLayer")
if err = os.MkdirAll(preparing, 0777); err != nil {
t.Fatal(err)
}
_, err = snapshotter.View(ctx, viewLayer, snapA)
if err != nil {
t.Fatal(err)
}
_, err = snapshotter.View(ctx, viewLayer, snapA)
//must be err != nil
assert.NotNil(t, err)
}