forked from neotoolkit/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid_test.go
51 lines (44 loc) · 895 Bytes
/
uuid_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 faker_test
import (
"regexp"
"testing"
"github.com/neotoolkit/faker"
)
func TestFaker_UUID(t *testing.T) {
t.Parallel()
f := faker.New()
uuid := f.UUID()
matchUUID(t, uuid)
}
func TestUUID(t *testing.T) {
t.Parallel()
uuid := faker.UUID()
matchUUID(t, uuid)
}
func matchUUID(t *testing.T, uuid string) {
t.Helper()
match, err := regexp.MatchString("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", uuid)
if err != nil {
t.Error(err)
}
if !match {
t.Error("want true, got false")
}
}
func TestFaker_UUID_UniqueInSequence(t *testing.T) {
t.Parallel()
f := faker.New()
last := f.UUID()
current := f.UUID()
if last == current {
t.Error("want unique uuid")
}
}
func TestUUID_UniqueInSequence(t *testing.T) {
t.Parallel()
last := faker.UUID()
current := faker.UUID()
if last == current {
t.Error("want unique uuid")
}
}