From 5e8218a63b468ea7ca19fe043c109cda45784570 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 14 Nov 2017 02:26:22 +0000 Subject: [PATCH] snapshot: fix specification of Commit The default implementations remove the key after Commit. However, the specification had required implementations not to remove the key. Signed-off-by: Akihiro Suda --- snapshot/snapshotter.go | 4 +--- snapshot/testsuite/testsuite.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/snapshot/snapshotter.go b/snapshot/snapshotter.go index 2b3fe6275..99768e560 100644 --- a/snapshot/snapshotter.go +++ b/snapshot/snapshotter.go @@ -280,9 +280,7 @@ type Snapshotter interface { // A committed snapshot will be created under name with the parent of the // active snapshot. // - // Commit may be called multiple times on the same key. Snapshots created - // in this manner will all reference the parent used to start the - // transaction. + // After commit, the snapshot identified by key is removed. Commit(ctx context.Context, name, key string, opts ...Opt) error // Remove the committed or active snapshot by the provided key. diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index 04443891f..4eec3d09c 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -143,6 +143,11 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh assert.Equal(t, "", si.Parent) assert.Equal(t, snapshot.KindCommitted, si.Kind) + _, err = snapshotter.Stat(ctx, preparing) + if err == nil { + t.Fatalf("%s should no longer be available after Commit", preparing) + } + next := filepath.Join(work, "nextlayer") if err := os.MkdirAll(next, 0777); err != nil { t.Fatalf("failure reason: %+v", err) @@ -186,6 +191,11 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh assert.Equal(t, committed, si2.Parent) assert.Equal(t, snapshot.KindCommitted, si2.Kind) + _, err = snapshotter.Stat(ctx, next) + if err == nil { + t.Fatalf("%s should no longer be available after Commit", next) + } + expected := map[string]snapshot.Info{ si.Name: si, si2.Name: si2,