-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
hash_test.go
71 lines (60 loc) · 1.47 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package utils
import (
"crypto/sha256"
"testing"
"github.com/Laisky/zap"
"github.com/stretchr/testify/require"
"github.com/Laisky/go-utils/v5/log"
)
const (
testhashraw = "dfij3ifj2jjl2jelkjdkwef"
)
func TestHashSHA128String(t *testing.T) {
t.Parallel()
val := testhashraw
got := HashSHA128String(val)
if got != "57dce855bbee0bef97b63527d473c807a424511d" {
t.Fatalf("got: %v", got)
}
}
func ExampleHashSHA128String() {
val := testhashraw
got := HashSHA128String(val)
log.Shared.Info("hash", zap.String("got", got))
}
func TestHashSHA256String(t *testing.T) {
t.Parallel()
val := testhashraw
got := HashSHA256String(val)
if got != "fef14c65b3d411fee6b2dbcb791a9536cbf637b153bb1de0aae1b41e3834aebf" {
t.Fatalf("got: %v", got)
}
t.Run("hasher", func(t *testing.T) {
t.Parallel()
raw := []byte("hello, world")
hasher := sha256.New()
_, err := hasher.Write(raw)
require.NoError(t, err)
got1 := hasher.Sum(nil)
got2 := sha256.Sum256(raw)
require.Equal(t, got1, got2[:])
})
}
func ExampleHashSHA256String() {
val := testhashraw
got := HashSHA256String(val)
log.Shared.Info("hash", zap.String("got", got))
}
func TestHashXxhashString(t *testing.T) {
t.Parallel()
val := testhashraw
got := HashXxhashString(val)
if got != "6466696a3369666a326a6a6c326a656c6b6a646b776566ef46db3751d8e999" {
t.Fatalf("got: %v", got)
}
}
func ExampleHashXxhashString() {
val := testhashraw
got := HashXxhashString(val)
log.Shared.Info("hash", zap.String("got", got))
}