This commit is contained in:
Zach Wasserman 2020-12-23 08:32:06 -08:00
parent 0c232ed07f
commit a69feb558d
2 changed files with 4 additions and 4 deletions

View file

@ -51,7 +51,7 @@ func DownloadWithSHA512Hash(url string, out io.Writer, size int64, expectedHash
// Validate the hash matches
gotHash := hash.Sum(nil)
if bytes.Compare(gotHash, expectedHash) != 0 {
if !bytes.Equal(gotHash, expectedHash) {
return errors.Errorf(
"hash %s does not match expected %s",
base64.StdEncoding.EncodeToString(gotHash),

View file

@ -41,7 +41,7 @@ func TestDownloadWithSHA512Hash(t *testing.T) {
expectedHash, expectedLen := sha512Hash(expectedData), int64(len(expectedData))
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(expectedData))
fmt.Fprint(w, string(expectedData))
}))
defer ts.Close()
@ -59,7 +59,7 @@ func TestDownloadWithSHA512HashTooSmall(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Don't write all of data
fmt.Fprintf(w, string(expectedData[:2]))
fmt.Fprint(w, string(expectedData[:2]))
}))
defer ts.Close()
@ -93,7 +93,7 @@ func TestDownloadWithSHA512HashMismatch(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Write non-matching data
fmt.Fprintf(w, string("def"))
fmt.Fprint(w, string("def"))
}))
defer ts.Close()