From d72fb9bcb34778ee2beb70c054a489c4d58643a3 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Thu, 17 Jan 2019 20:26:16 +0000 Subject: [PATCH] If checksums for a download don't match, display the checksum that was found --- common/download.go | 5 +++-- common/download_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/download.go b/common/download.go index 78f31f25d..a5b217a62 100644 --- a/common/download.go +++ b/common/download.go @@ -191,8 +191,9 @@ func (d *DownloadClient) Get() (string, error) { } err = fmt.Errorf( - "checksums didn't match expected: %s", - hex.EncodeToString(d.config.Checksum)) + "checksums didn't match. expected %s and got %s", + hex.EncodeToString(d.config.Checksum), + hex.EncodeToString(d.config.Hash.Sum(nil))) } } diff --git a/common/download_test.go b/common/download_test.go index dd41d6cc1..be4382393 100644 --- a/common/download_test.go +++ b/common/download_test.go @@ -411,7 +411,7 @@ func TestDownloadFileUrl(t *testing.T) { // Verify that we fail to match the checksum _, err = client.Get() - if err.Error() != "checksums didn't match expected: 6e6f7065" { + if err.Error() != "checksums didn't match. expected 6e6f7065 and got 606f1945f81a022d0ed0bd99edfd4f99081c1cb1f97fae087291ee14e945e608" { t.Fatalf("Unexpected failure; expected checksum not to match. Error was \"%v\"", err) } @@ -442,7 +442,7 @@ func SimulateFileUriDownload(t *testing.T, uri string) (string, error) { path, err := client.Get() // ignore any non-important checksum errors if it's not a unc path - if !strings.HasPrefix(path, "\\\\") && err.Error() != "checksums didn't match expected: 6e6f7065" { + if !strings.HasPrefix(path, "\\\\") && err.Error() != "checksums didn't match. expected 6e6f7065 and got 606f1945f81a022d0ed0bd99edfd4f99081c1cb1f97fae087291ee14e945e608" { t.Fatalf("Unexpected failure; expected checksum not to match") }