nit: output snapshot ID when --json is used (#921)

This commit is contained in:
Jarek Kowalski authored and GitHub committed 2021-04-02 19:58:17 -07:00
1 parent 9a756c719f
commit 8beb265c27
3 files changed
+17 -1

No files matched your search

+4
View File
@@ -123,6 +123,10 @@ func SaveSnapshot(ctx context.Context, rep repo.RepositoryWriter, man *Manifest)
return "", errors.New("missing path")
}
// clear manifest ID in case it was set, since we'll be generating a new one and we don't want
// to write previous ID in JSON.
man.ID = ""
id, err := rep.PutManifest(ctx, sourceInfoToLabels(man.Source), man)
if err != nil {
return "", errors.Wrap(err, "error putting manifest")
+1 -1
View File
@@ -15,7 +15,7 @@ import (
// Manifest represents information about a single point-in-time filesystem snapshot.
type Manifest struct {
ID manifest.ID `json:"-"`
ID manifest.ID `json:"id"`
Source SourceInfo `json:"source"`
Description string `json:"description"`
@@ -46,10 +46,22 @@ func TestSnapshotCreate(t *testing.T) {
mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2, "--json"), &man1)
mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2, "--json"), &man2)
if man1.ID == "" {
t.Fatalf("missing root id")
}
if man2.ID == "" {
t.Fatalf("missing root id")
}
if man1.RootEntry.ObjectID == "" {
t.Fatalf("missing root id")
}
if man1.ID == man2.ID {
t.Fatalf("unexpectedly identical snapshot IDs: %v", man1.ID)
}
if man1.RootEntry.ObjectID != man2.RootEntry.ObjectID {
t.Fatalf("unexpected difference in root objects %v vs %v", man1.RootEntry.ObjectID, man2.RootEntry.ObjectID)
}