Add snapshot walk implementations
Temporarily remove zfs and aufs until interface update Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -49,6 +50,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
|
||||
t.Run("PreareViewFailingtest", makeTest(name, snapshotterFn, checkSnapshotterPrepareView))
|
||||
t.Run("Update", makeTest(name, snapshotterFn, checkUpdate))
|
||||
t.Run("Remove", makeTest(name, snapshotterFn, checkRemove))
|
||||
t.Run("Walk", makeTest(name, snapshotterFn, checkWalk))
|
||||
|
||||
t.Run("LayerFileupdate", makeTest(name, snapshotterFn, checkLayerFileUpdate))
|
||||
t.Run("RemoveDirectoryInLowerLayer", makeTest(name, snapshotterFn, checkRemoveDirectoryInLowerLayer))
|
||||
@@ -961,3 +963,135 @@ func check128LayersMount(name string) func(ctx context.Context, t *testing.T, sn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkWalk(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
opt := snapshots.WithLabels(map[string]string{
|
||||
"containerd.io/gc.root": "check-walk",
|
||||
})
|
||||
|
||||
// No parent active
|
||||
if _, err := snapshotter.Prepare(ctx, "a-np", "", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Base parent
|
||||
if _, err := snapshotter.Prepare(ctx, "p-tmp", "", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := snapshotter.Commit(ctx, "p", "p-tmp", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Active
|
||||
if _, err := snapshotter.Prepare(ctx, "a", "p", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// View
|
||||
if _, err := snapshotter.View(ctx, "v", "p", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Base parent with label=1
|
||||
if _, err := snapshotter.Prepare(ctx, "p-wl-tmp", "", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := snapshotter.Commit(ctx, "p-wl", "p-wl-tmp", snapshots.WithLabels(map[string]string{
|
||||
"l": "1",
|
||||
"containerd.io/gc.root": "check-walk",
|
||||
})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// active with label=2
|
||||
if _, err := snapshotter.Prepare(ctx, "a-wl", "p-wl", snapshots.WithLabels(map[string]string{
|
||||
"l": "2",
|
||||
"containerd.io/gc.root": "check-walk",
|
||||
})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// view with label=3
|
||||
if _, err := snapshotter.View(ctx, "v-wl", "p-wl", snapshots.WithLabels(map[string]string{
|
||||
"l": "3",
|
||||
"containerd.io/gc.root": "check-walk",
|
||||
})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// no parent active with label=2
|
||||
if _, err := snapshotter.Prepare(ctx, "a-np-wl", "", snapshots.WithLabels(map[string]string{
|
||||
"l": "2",
|
||||
"containerd.io/gc.root": "check-walk",
|
||||
})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, tc := range []struct {
|
||||
matches []string
|
||||
filters []string
|
||||
}{
|
||||
{
|
||||
matches: []string{"a-np", "p", "a", "v", "p-wl", "a-wl", "v-wl", "a-np-wl"},
|
||||
filters: []string{"labels.\"containerd.io/gc.root\"==check-walk"},
|
||||
},
|
||||
{
|
||||
matches: []string{"a-np", "a", "a-wl", "a-np-wl"},
|
||||
filters: []string{"kind==active,labels.\"containerd.io/gc.root\"==check-walk"},
|
||||
},
|
||||
{
|
||||
matches: []string{"v", "v-wl"},
|
||||
filters: []string{"kind==view,labels.\"containerd.io/gc.root\"==check-walk"},
|
||||
},
|
||||
{
|
||||
matches: []string{"p", "p-wl"},
|
||||
filters: []string{"kind==committed,labels.\"containerd.io/gc.root\"==check-walk"},
|
||||
},
|
||||
{
|
||||
matches: []string{"p", "a-np-wl"},
|
||||
filters: []string{"name==p", "name==a-np-wl"},
|
||||
},
|
||||
{
|
||||
matches: []string{"a-wl"},
|
||||
filters: []string{"name==a-wl,labels.l"},
|
||||
},
|
||||
{
|
||||
matches: []string{"a", "v"},
|
||||
filters: []string{"parent==p"},
|
||||
},
|
||||
{
|
||||
matches: []string{"a", "v", "a-wl", "v-wl"},
|
||||
filters: []string{"parent,labels.\"containerd.io/gc.root\"==check-walk"},
|
||||
},
|
||||
{
|
||||
matches: []string{"p-wl", "a-wl", "v-wl", "a-np-wl"},
|
||||
filters: []string{"labels.l"},
|
||||
},
|
||||
{
|
||||
matches: []string{"a-wl", "a-np-wl"},
|
||||
filters: []string{"labels.l==2"},
|
||||
},
|
||||
} {
|
||||
actual := []string{}
|
||||
err := snapshotter.Walk(ctx, func(ctx context.Context, si snapshots.Info) error {
|
||||
actual = append(actual, si.Name)
|
||||
return nil
|
||||
}, tc.filters...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sort.Strings(tc.matches)
|
||||
sort.Strings(actual)
|
||||
if len(actual) != len(tc.matches) {
|
||||
t.Errorf("[%d] Unexpected result (size):\nActual:\n\t%#v\nExpected:\n\t%#v", i, actual, tc.matches)
|
||||
continue
|
||||
}
|
||||
for j := range actual {
|
||||
if actual[j] != tc.matches[j] {
|
||||
t.Errorf("[%d] Unexpected result @%d:\nActual:\n\t%#vExpected:\n\t%#v", i, j, actual, tc.matches)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user