| 1 |
package plumbing |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
. "gopkg.in/check.v1" |
| 7 |
) |
| 8 |
|
| 9 |
func Test(t *testing.T) { TestingT(t) } |
| 10 |
|
| 11 |
type HashSuite struct{} |
| 12 |
|
| 13 |
var _ = Suite(&HashSuite{}) |
| 14 |
|
| 15 |
func (s *HashSuite) TestComputeHash(c *C) { |
| 16 |
hash := ComputeHash(BlobObject, []byte("")) |
| 17 |
c.Assert(hash.String(), Equals, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391") |
| 18 |
|
| 19 |
hash = ComputeHash(BlobObject, []byte("Hello, World!\n")) |
| 20 |
c.Assert(hash.String(), Equals, "8ab686eafeb1f44702738c8b0f24f2567c36da6d") |
| 21 |
} |
| 22 |
|
| 23 |
func (s *HashSuite) TestNewHash(c *C) { |
| 24 |
hash := ComputeHash(BlobObject, []byte("Hello, World!\n")) |
| 25 |
|
| 26 |
c.Assert(hash, Equals, NewHash(hash.String())) |
| 27 |
} |
| 28 |
|
| 29 |
func (s *HashSuite) TestIsZero(c *C) { |
| 30 |
hash := NewHash("foo") |
| 31 |
c.Assert(hash.IsZero(), Equals, true) |
| 32 |
|
| 33 |
hash = NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d") |
| 34 |
c.Assert(hash.IsZero(), Equals, false) |
| 35 |
} |
| 36 |
|
| 37 |
func (s *HashSuite) TestNewHasher(c *C) { |
| 38 |
content := "hasher test sample" |
| 39 |
hasher := NewHasher(BlobObject, int64(len(content))) |
| 40 |
hasher.Write([]byte(content)) |
| 41 |
c.Assert(hasher.Sum().String(), Equals, "dc42c3cc80028d0ec61f0a6b24cadd1c195c4dfc") |
| 42 |
} |
| 43 |
|
| 44 |
func (s *HashSuite) TestHashesSort(c *C) { |
| 45 |
i := []Hash{ |
| 46 |
NewHash("2222222222222222222222222222222222222222"), |
| 47 |
NewHash("1111111111111111111111111111111111111111"), |
| 48 |
} |
| 49 |
|
| 50 |
HashesSort(i) |
| 51 |
|
| 52 |
c.Assert(i[0], Equals, NewHash("1111111111111111111111111111111111111111")) |
| 53 |
c.Assert(i[1], Equals, NewHash("2222222222222222222222222222222222222222")) |
| 54 |
} |
| 55 |
|
| 56 |
func (s *HashSuite) TestIsHash(c *C) { |
| 57 |
c.Assert(IsHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"), Equals, true) |
| 58 |
c.Assert(IsHash("foo"), Equals, false) |
| 59 |
c.Assert(IsHash("zab686eafeb1f44702738c8b0f24f2567c36da6d"), Equals, false) |
| 60 |
} |