mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-23 02:40:49 -05:00
Add test for ref.FromHash
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user