-
Notifications
You must be signed in to change notification settings - Fork 3
/
autohash_test.go
51 lines (43 loc) · 1.17 KB
/
autohash_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"testing"
)
func TestAutoHashes(t *testing.T) {
ah := autohashNew("md5", "djb2", "djb2a", "sha256", "shake-256-64")
ah.Write([]byte("abcd"))
data := []struct {
chk string
res string
}{
{"md5", "e2fc714c4727ee9395f324cd2e7f331f"},
{"djb2", "7c93ee4f"},
{"djb2a", "7c6d8341"},
{"sha256", "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"},
{"shake-256-64", "16c60651e6448eb9c177234fdd73ce60cbfe6d805c0e8f4c956986376be286d6787e6e2e0b8d1aeb7711e9a097cb592fc7043b5eb045d43afc1fae7b3aa2fa36"},
}
chks := ah.Checksums()
for i := range data {
chk := data[i].chk
res := data[i].res
if chk != chks[i].Kind {
t.Errorf("chksum not equl:\n tst=<%s>\n got <%s>\n",
chk, chks[i].Kind)
}
tst := fmt.Sprintf("%x", chks[i].Data)
if res != fmt.Sprintf("%x", chks[i].Data) {
t.Errorf("data not equl:\n tst=<%s>\n got <%s>\n",
res, tst)
}
}
}
func TestLenBytes(t *testing.T) {
for i := range validChecksumKinds {
kind := validChecksumKinds[i]
chk := chkNew(kind)
if chk.Size() != chkSize(kind) {
t.Errorf("chkLenBytes not equl(%s):\n tst=<%d>\n got <%d>\n",
kind, chk.Size(), chkSize(kind))
}
}
}