-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv4_test.go
68 lines (53 loc) · 1.3 KB
/
v4_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
package uuid_test
import (
"testing"
"github.com/DaanV2/go-uuid"
"github.com/stretchr/testify/require"
)
func Test_V4_Version(t *testing.T) {
require.Equal(t, uuid.Version4, uuid.V4.Version())
}
func Test_V4_Variant(t *testing.T) {
require.Equal(t, uuid.Variant1, uuid.V4.Variant())
}
func Test_V4_New(t *testing.T) {
u := uuid.V4.New()
Expect_Valid_UUID(t, u, uuid.V4.Version(), uuid.V4.Variant())
}
func Test_V4_NewHex(t *testing.T) {
u := uuid.V4.NewHex()
require.Len(t, u, 32)
require.NotRegexp(t, "[^a-zA-Z0-9]", u)
}
func Test_V4_NewString(t *testing.T) {
u := uuid.V4.NewString()
require.Len(t, u, 36)
require.NotRegexp(t, "[^a-zA-Z0-9-]", u)
err := uuid.ValidateStringUUID(u)
require.NoError(t, err)
}
func Test_V4_NewBatch(t *testing.T) {
sizes := []int{
1 * uuid.TOTAL_BYTES,
2 * uuid.TOTAL_BYTES,
3 * uuid.TOTAL_BYTES,
16 * uuid.TOTAL_BYTES,
16 * uuid.TOTAL_BYTES - 1,
1000_000,
}
for _, size := range sizes {
t.Run("NewBatch", func(t *testing.T) {
batch := uuid.V4.NewBatch(size)
require.Len(t, batch, size)
uni := make(map[string]bool)
for _, u := range batch {
Expect_Valid_UUID(t, u, uuid.V4.Version(), uuid.V4.Variant())
if has, ok := uni[u.String()]; ok {
require.False(t, has)
} else {
uni[u.String()] = true
}
}
})
}
}