-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
hash_test.go
43 lines (38 loc) · 850 Bytes
/
hash_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
package faker
import (
"fmt"
"testing"
)
// Check if input is hex encoded string
func checkIfHexString(s string) bool {
for i := 0; i < len(s); i++ {
if !((s[i] >= 97 && s[i] <= 102) || (s[i] >= 48 && s[i] <= 57)) {
return false
}
}
return true
}
// tests SHA256()
func TestSHA256(t *testing.T) {
hash := New().Hash()
s := hash.SHA256()
Expect(t, fmt.Sprintf("%T", s), "string")
Expect(t, 64, len(s))
Expect(t, true, checkIfHexString(s))
}
// tests SHA512()
func TestSHA512(t *testing.T) {
hash := New().Hash()
s := hash.SHA512()
Expect(t, fmt.Sprintf("%T", s), "string")
Expect(t, 128, len(s))
Expect(t, true, checkIfHexString(s))
}
// tests MD5()
func TestMD5(t *testing.T) {
hash := New().Hash()
s := hash.MD5()
Expect(t, fmt.Sprintf("%T", s), "string")
Expect(t, 32, len(s))
Expect(t, true, checkIfHexString(s))
}