Skip to content

Commit

Permalink
Merge pull request #3793 from dmcgowan/prepare-snapshot-target
Browse files Browse the repository at this point in the history
Support target snapshot references on prepare
  • Loading branch information
AkihiroSuda committed Nov 26, 2019
2 parents 383f4a7 + 526c0db commit 45fb5ae
Show file tree
Hide file tree
Showing 6 changed files with 564 additions and 51 deletions.
4 changes: 1 addition & 3 deletions metadata/adaptors.go
Expand Up @@ -159,9 +159,7 @@ func adaptSnapshot(info snapshots.Info) filters.Adaptor {
case "name":
return info.Name, true
case "parent":
if info.Parent != "" {
return info.Parent, true
}
return info.Parent, true
case "labels":
return checkMap(fieldpath[1:], info.Labels)
}
Expand Down
38 changes: 36 additions & 2 deletions metadata/db_test.go
Expand Up @@ -48,9 +48,31 @@ import (
bolt "go.etcd.io/bbolt"
)

func testDB(t *testing.T) (context.Context, *DB, func()) {
type testOptions struct {
extraSnapshots map[string]func(string) (snapshots.Snapshotter, error)
}

type testOpt func(*testOptions)

func withSnapshotter(name string, fn func(string) (snapshots.Snapshotter, error)) testOpt {
return func(to *testOptions) {
if to.extraSnapshots == nil {
to.extraSnapshots = map[string]func(string) (snapshots.Snapshotter, error){}
}
to.extraSnapshots[name] = fn
}
}

func testDB(t *testing.T, opt ...testOpt) (context.Context, *DB, func()) {
ctx, cancel := context.WithCancel(context.Background())
ctx = namespaces.WithNamespace(ctx, "testing")
ctx = logtest.WithT(ctx, t)

var topts testOptions

for _, o := range opt {
o(&topts)
}

dirname, err := ioutil.TempDir("", strings.Replace(t.Name(), "/", "_", -1)+"-")
if err != nil {
Expand All @@ -62,6 +84,18 @@ func testDB(t *testing.T) (context.Context, *DB, func()) {
t.Fatal(err)
}

snapshotters := map[string]snapshots.Snapshotter{
"native": snapshotter,
}

for name, fn := range topts.extraSnapshots {
snapshotter, err := fn(filepath.Join(dirname, name))
if err != nil {
t.Fatal(err)
}
snapshotters[name] = snapshotter
}

cs, err := local.NewStore(filepath.Join(dirname, "content"))
if err != nil {
t.Fatal(err)
Expand All @@ -72,7 +106,7 @@ func testDB(t *testing.T) (context.Context, *DB, func()) {
t.Fatal(err)
}

db := NewDB(bdb, cs, map[string]snapshots.Snapshotter{"native": snapshotter})
db := NewDB(bdb, cs, snapshotters)
if err := db.Init(ctx); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 45fb5ae

Please sign in to comment.