zip: include 'but content has correct sum' note in TestVCS When TestVCS fails because the zip file hash changes, something that is expected whenever the zip algorithm improves, it's useful to see a reassuring note that the actual content within the zip file still has the correct sum. This enhancement is adapted from cmd/go/internal/modfetch.TestCodeRepo where I saw it before. For golang/go#66927. Change-Id: Ia78bbfaf0513be5f7b6a7d1dd8ee800447ed2c07 Cq-Include-Trybots: luci.golang.try:x_mod-gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/mod/+/772780 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/zip/zip_test.go b/zip/zip_test.go index 84560f6..52757ce 100644 --- a/zip/zip_test.go +++ b/zip/zip_test.go
@@ -1360,17 +1360,19 @@ } gotZipHash := hex.EncodeToString(h.Sum(nil)) - if test.wantZipHash != gotZipHash { + if gotZipHash != test.wantZipHash { // If the test fails because the hash of the zip file itself differs, // that may be okay as long as the hash of the data within the zip file // does not change. For example, we might change the compression, // order, or alignment of files without affecting the extracted output. // We shouldn't make such a change unintentionally though, so this // test will fail either way. - if gotSum, err := dirhash.HashZip(tmpModZipPath, dirhash.Hash1); err == nil && test.wantContentHash != gotSum { - t.Fatalf("zip content hash: got %s, want %s", gotSum, test.wantContentHash) + if gotSum, err := dirhash.HashZip(tmpModZipPath, dirhash.Hash1); err != nil { + t.Fatal("dirhash.HashZip:", err) + } else if gotSum != test.wantContentHash { + t.Fatalf("got file with sum %q, want %q", gotSum, test.wantContentHash) } else { - t.Fatalf("zip file hash: got %s, want %s", gotZipHash, test.wantZipHash) + t.Fatalf("got file with hash %q, want %q (but content has correct sum)", gotZipHash, test.wantZipHash) } } })