Add test for ref.FromHash

This commit is contained in:
Aaron Boodman
2015-07-01 23:08:47 -07:00
parent 302042e387
commit 369e2a1cda
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -40,8 +40,8 @@ func NewHash() hash.Hash {
return sha1.New()
}
// TODO: Test.
func FromHash(h hash.Hash) Ref {
Chk.Equal(sha1.Size, h.Size())
digest := Sha1Digest{}
h.Sum(digest[:0])
return New(digest)
+8
View File
@@ -3,6 +3,7 @@ package ref
import (
"testing"
"go/src/pkg/crypto/sha1"
"github.com/stretchr/testify/assert"
)
@@ -60,3 +61,10 @@ func TestDigest(t *testing.T) {
d[0] = 0x01
assert.NotEqual(t, r.Digest(), d)
}
func TestFromHash(t *testing.T) {
h := sha1.New()
h.Write([]byte("abc"))
r := FromHash(h)
assert.Equal(t, "sha1-a9993e364706816aba3e25717850c26c9cd0d89d", r.String())
}