-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathids_test.go
77 lines (59 loc) · 1.51 KB
/
ids_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
72
73
74
75
76
77
package stdlib
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChecksum(t *testing.T) {
cs1 := Checksum("check me")
result1 := "10f335e9"
result2 := "00000000"
assert.NotEmpty(t, cs1)
assert.Equal(t, result1, cs1)
cs2 := Checksum("")
assert.NotEmpty(t, cs2)
assert.Equal(t, result2, cs2)
}
func TestFingerprint(t *testing.T) {
cs1 := Fingerprint("check me")
result1 := "6e7227eb9fb0793b0e150facda30c40b"
result2 := "d41d8cd98f00b204e9800998ecf8427e"
assert.NotEmpty(t, cs1)
assert.Equal(t, result1, cs1)
cs2 := Fingerprint("")
assert.NotEmpty(t, cs2)
assert.Equal(t, result2, cs2)
}
func TestUUID(t *testing.T) {
uuid, err := UUID()
assert.NotEmpty(t, uuid)
assert.NoError(t, err)
parts := strings.Split(uuid, "-")
assert.Equal(t, 5, len(parts))
assert.Equal(t, 8, len(parts[0]))
assert.Equal(t, 4, len(parts[1]))
assert.Equal(t, 4, len(parts[2]))
assert.Equal(t, 4, len(parts[3]))
assert.Equal(t, 12, len(parts[4]))
}
func TestRandomToken(t *testing.T) {
prefix := "xoxo"
token, err := RandomToken(prefix)
assert.NotEmpty(t, token)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(token, prefix))
parts := strings.Split(token, "-")
assert.Equal(t, 3, len(parts))
}
func TestShortUUID(t *testing.T) {
uuid, err := ShortUUID()
assert.NotEmpty(t, uuid)
assert.NoError(t, err)
assert.Equal(t, 12, len(uuid))
}
func TestSimpleUUID(t *testing.T) {
uuid, err := SimpleUUID()
assert.NotEmpty(t, uuid)
assert.NoError(t, err)
assert.Equal(t, 32, len(uuid))
}