Merge pull request #581 from kunalkushwaha/testsuite-transitive
Testcase to test Transitivity of snapshot layers.
This commit is contained in:
commit
2831e9b469
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("Basic", makeTest(t, name, snapshotterFn, checkSnapshotterBasic))
|
||||||
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))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -87,3 +88,79 @@ func checkSnapshotterStatCommitted(t *testing.T, snapshotter Snapshotter, work s
|
||||||
assert.Equal(t, "", si.Parent)
|
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