Skip to content

Commit

Permalink
feat: add destination name to error messages
Browse files Browse the repository at this point in the history
Makes them more useful.

Signed-off-by: Alexey Palazhchenko <[email protected]>
  • Loading branch information
AlekSi committed Jul 29, 2021
1 parent 3198175 commit 6ffa6b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/pkg/types/v1alpha2/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ func (source *Source) ValidateChecksums(ctx context.Context) (string, string, er
)

if actualSHA256 = hex.EncodeToString(s256.Sum(nil)); source.SHA256 != actualSHA256 {
multiErr = multierror.Append(multiErr, fmt.Errorf("source.sha256 does not match: expected %s, got %s", source.SHA256, actualSHA256))
err = fmt.Errorf("%s sha256 does not match: expected %s, got %s", source.Destination, source.SHA256, actualSHA256)
multiErr = multierror.Append(multiErr, err)
}

if actualSHA512 = hex.EncodeToString(s512.Sum(nil)); source.SHA512 != actualSHA512 {
multiErr = multierror.Append(multiErr, fmt.Errorf("source.sha512 does not match: expected %s, got %s", source.SHA512, actualSHA512))
err = fmt.Errorf("%s sha512 does not match: expected %s, got %s", source.Destination, source.SHA512, actualSHA512)
multiErr = multierror.Append(multiErr, err)
}

return actualSHA256, actualSHA512, multiErr.ErrorOrNil()
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/types/v1alpha2/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestSourceValidateChecksums(t *testing.T) {

actualSHA256, actualSHA512, err = source.ValidateChecksums(context.Background())
assert.EqualError(t, err, `2 errors occurred:
* source.sha256 does not match: expected 0000000000000000000000000000000000000000000000000000000000000000, got 2aa5f088cbb332e73fc3def546800616b38d3bfe6b8713b8a6404060f22503e8
* source.sha512 does not match: expected 1111111111111111111111111111111111111111111111111111111111111111, got ce64105ff71615f9d235cc7c8656b6409fc40cc90d15a28d355fadd9072d2eab842af379dd8bba0f1181715753143e4a07491e0f9e5f8df806327d7c95a34fae
* go1.12.5.src.tar.gz sha256 does not match: expected 0000000000000000000000000000000000000000000000000000000000000000, got 2aa5f088cbb332e73fc3def546800616b38d3bfe6b8713b8a6404060f22503e8
* go1.12.5.src.tar.gz sha512 does not match: expected 1111111111111111111111111111111111111111111111111111111111111111, got ce64105ff71615f9d235cc7c8656b6409fc40cc90d15a28d355fadd9072d2eab842af379dd8bba0f1181715753143e4a07491e0f9e5f8df806327d7c95a34fae
`)
assert.Equal(t, expectedSHA256, actualSHA256)
Expand Down

0 comments on commit 6ffa6b2

Please sign in to comment.