diff --git a/pkg/restic/restic.go b/pkg/restic/restic.go index bcaa927aee..0b9cc0a3e3 100644 --- a/pkg/restic/restic.go +++ b/pkg/restic/restic.go @@ -206,7 +206,7 @@ func SnapshotIDFromSnapshotLog(output string) (string, error) { if err != nil { return "", errors.WithMessage(err, "Failed to unmarshall output from snapshotCommand") } - if len(result) != 1 { + if len(result) == 0 { return "", errors.New("Snapshot not found") } snapId := result[0]["short_id"] diff --git a/pkg/restic/restic_test.go b/pkg/restic/restic_test.go index a3f7ecd2bc..5877128e3c 100644 --- a/pkg/restic/restic_test.go +++ b/pkg/restic/restic_test.go @@ -36,7 +36,7 @@ func (s *ResticDataSuite) TestGetSnapshotIDFromTag(c *C) { checker Checker }{ {log: `[{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"}]`, expected: "7c0bfeb9", checker: IsNil}, - {log: `[{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"},{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"}]`, expected: "", checker: NotNil}, + {log: `[{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"},{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"}]`, expected: "7c0bfeb9", checker: IsNil}, {log: `null`, expected: "", checker: NotNil}, } { id, err := SnapshotIDFromSnapshotLog(tc.log)