Skip to content

Commit

Permalink
Add extra test check for ContentHash() where different sha3_384 check…
Browse files Browse the repository at this point in the history
…sums inside Snapshot lead to different hash (thanks ijohnson)
  • Loading branch information
stolowski committed Jan 13, 2021
1 parent 17763ae commit e285953
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ func (cs *clientSuite) TestClientSnapshotContentHash(c *check.C) {
h3, err := sh3.ContentHash()
c.Assert(err, check.IsNil)
c.Check(h1, check.Not(check.DeepEquals), h3)

// identical to sh1 except for sha3_384 sums
sums4 := map[string]string{"user/foo.tgz": "some other hash"}
sh4 := &client.Snapshot{SetID: 1, Time: now, Snap: "asnap", Revision: revno, SHA3_384: sums4}
// same except sha3_384 means different hash
h4, err := sh4.ContentHash()
c.Assert(err, check.IsNil)
c.Check(h4, check.Not(check.DeepEquals), h1)
}

func (cs *clientSuite) TestClientSnapshotSetContentHash(c *check.C) {
Expand Down
2 changes: 1 addition & 1 deletion overlord/snapshotstate/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func (s *snapshotSuite) TestImportDuplicated(c *check.C) {
_, err = backend.Import(ctx, 123, buf)
dupErr, ok := err.(backend.DuplicatedSnapshotImportError)
c.Assert(ok, check.Equals, true)
c.Check(dupErr.SetID, check.Equals, shID)
c.Assert(dupErr, check.DeepEquals, backend.DuplicatedSnapshotImportError{SetID: shID})
}

func (s *snapshotSuite) TestImportExportRoundtrip(c *check.C) {
Expand Down
2 changes: 1 addition & 1 deletion tests/main/snapshot-basic/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ execute: |
NUM_SAVED=$(snap saved | wc -l)
echo "Import again doesn't create a duplicated snapshot"
IMPORTED_ID=$( snap import-snapshot "${SET_ID}_export.snapshot" | head -n1 | cut -f2 -d'#' )
IMPORTED_ID=$( snap import-snapshot "${SET_ID}_export-2.snapshot" | head -n1 | cut -f2 -d'#' )
[[ "$RESTORE_ID" == "$IMPORTED_ID" ]]
[[ "$NUM_SAVED" == $(snap saved | wc -l) ]]
Expand Down

0 comments on commit e285953

Please sign in to comment.