Testcase for Transitivity of snapshot layers.
Given snapshots A <- B <- C, B is the parent of C and A is a transitive parent of C Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
This commit is contained in:
parent
78e4c590a0
commit
8bbce4b80f
2 changed files with 79 additions and 0 deletions
|
@ -219,6 +219,8 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(root string)
|
|||
t.Run("Basic", makeTest(t, name, snapshotterFn, checkSnapshotterBasic))
|
||||
t.Run("StatActive", makeTest(t, name, snapshotterFn, checkSnapshotterStatActive))
|
||||
t.Run("StatComitted", makeTest(t, name, snapshotterFn, checkSnapshotterStatCommitted))
|
||||
t.Run("TransitivityTest", makeTest(t, name, snapshotterFn, checkSnapshotterTransitivity))
|
||||
|
||||
}
|
||||
|
||||
func makeTest(t *testing.T, name string, snapshotterFn func(root string) (Snapshotter, func(), error), fn func(t *testing.T, snapshotter Snapshotter, work string)) func(t *testing.T) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package snapshot
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -87,3 +88,79 @@ func checkSnapshotterStatCommitted(t *testing.T, snapshotter Snapshotter, work s
|
|||
assert.Equal(t, "", si.Parent)
|
||||
|
||||
}
|
||||
|
||||
func snapshotterPrepareMount(ctx context.Context, snapshotter Snapshotter, diffPathName string, parent string, work string) (string, error) {
|
||||
preparing := filepath.Join(work, diffPathName)
|
||||
if err := os.MkdirAll(preparing, 0777); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
mounts, err := snapshotter.Prepare(ctx, preparing, parent)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(mounts) < 1 {
|
||||
return "", fmt.Errorf("expected mounts to have entries")
|
||||
}
|
||||
|
||||
if err = containerd.MountAll(mounts, preparing); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return preparing, nil
|
||||
}
|
||||
|
||||
// Given A <- B <- C, B is the parent of C and A is a transitive parent of C (in this case, a "grandparent")
|
||||
func checkSnapshotterTransitivity(t *testing.T, snapshotter Snapshotter, work string) {
|
||||
ctx := context.TODO()
|
||||
preparing, err := snapshotterPrepareMount(ctx, snapshotter, "preparing", "", work)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer testutil.Unmount(t, preparing)
|
||||
|
||||
if err = ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
snapA := filepath.Join(work, "snapA")
|
||||
if err = snapshotter.Commit(ctx, snapA, preparing); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
next, err := snapshotterPrepareMount(ctx, snapshotter, "next", snapA, work)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer testutil.Unmount(t, next)
|
||||
|
||||
if err = ioutil.WriteFile(filepath.Join(next, "foo"), []byte("foo bar\n"), 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
snapB := filepath.Join(work, "snapB")
|
||||
if err = snapshotter.Commit(ctx, snapB, next); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
siA, err := snapshotter.Stat(ctx, snapA)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
siB, err := snapshotter.Stat(ctx, snapB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
siParentB, err := snapshotter.Stat(ctx, siB.Parent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test the transivity
|
||||
assert.Equal(t, "", siA.Parent)
|
||||
assert.Equal(t, snapA, siB.Parent)
|
||||
assert.Equal(t, "", siParentB.Parent)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue