digest: better test coverage

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2016-12-15 17:21:57 -08:00
parent 6a74c94bf8
commit ecb2ee3824
No known key found for this signature in database
GPG key ID: FB5F6B2905D7ECF3
4 changed files with 116 additions and 11 deletions

View file

@ -1,8 +1,6 @@
package digest
import (
_ "crypto/sha256"
_ "crypto/sha512"
"testing"
)
@ -28,6 +26,11 @@ func TestParseDigest(t *testing.T) {
input: "sha256:",
err: ErrDigestInvalidFormat,
},
{
// empty hex
input: ":",
err: ErrDigestInvalidFormat,
},
{
// just hex
input: "d41d8cd98f00b204e9800998ecf8427e",
@ -80,5 +83,10 @@ func TestParseDigest(t *testing.T) {
if newParsed != digest {
t.Fatalf("expected equal: %q != %q", newParsed, digest)
}
newFromHex := NewDigestFromHex(newParsed.Algorithm().String(), newParsed.Hex())
if newFromHex != digest {
t.Fatalf("%v != %v", newFromHex, digest)
}
}
}