Skip to content

Commit

Permalink
Return error only when count==0 (#267)
Browse files Browse the repository at this point in the history
 Return error only when count==0
  • Loading branch information
DeepikaDixit authored Sep 9, 2019
1 parent a354a36 commit 96d0164
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/restic/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/restic/restic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 96d0164

Please sign in to comment.