Skip to content

Commit

Permalink
internal/checksum: add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Jun 3, 2021
1 parent 2a2f94f commit 2ebdc3f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,48 @@
// license that can be found in the LICENSE file.

package checksum

import (
"bytes"
"crypto/rand"
"encoding/base64"
"testing"
)

func TestEncodedCrc32cChecksum(t *testing.T) {
var data [32]byte
_, err := rand.Read(data[:])
if err != nil {
t.Fatal(err)
}

encoded := EncodedCrc32cChecksum(data[:])
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
t.Fatal(err)
}

expected := crc32cChecksum(data[:])
if !bytes.Equal(decoded, expected) {
t.Errorf("incorrect value after decoding\nwant %x, got %x", expected, decoded)
}
}

func TestEncodedMd5Hash(t *testing.T) {
var data [32]byte
_, err := rand.Read(data[:])
if err != nil {
t.Fatal(err)
}

encoded := EncodedMd5Hash(data[:])
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
t.Fatal(err)
}

expected := MD5Hash(data[:])
if !bytes.Equal(decoded, expected) {
t.Errorf("incorrect value after decoding\nwant %x, got %x", expected, decoded)
}
}

0 comments on commit 2ebdc3f

Please sign in to comment.