-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
uuid_test.go
56 lines (49 loc) · 1.58 KB
/
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
52
53
54
55
56
package faker
import (
"fmt"
"reflect"
"regexp"
"testing"
)
func TestDigit(t *testing.T) {
p := GetIdentifier()
uuid, err := p.Digit(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if match, err := regexp.Match("^[a-zA-Z0-9]{32}$", []byte(uuid.(string))); !match || err != nil {
t.Errorf("Could not match the UUID format, err: %+v, match: %+v", err, match)
}
}
func TestHyphenated(t *testing.T) {
p := GetIdentifier()
uuid, err := p.Hyphenated(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
exp := "[a-zA-Z 0-9]"
pattern := fmt.Sprintf("^%s{8}-%s{4}-%s{4}-%s{4}-%s{12}$", exp, exp, exp, exp, exp)
if match, err := regexp.Match(pattern, []byte(uuid.(string))); !match || err != nil {
t.Errorf("Could not match the UUID hyphenated format, err: %+v, match: %+v", err, match)
}
}
func TestGetIdentifier(t *testing.T) {
identifier := GetIdentifier()
if identifier == nil {
t.Fatalf("TestGetIdentifier failed because identifier was nil")
}
}
func TestFakeDigit(t *testing.T) {
uuid := UUIDDigit()
if match, err := regexp.Match("^[a-zA-Z0-9]{32}$", []byte(uuid)); !match || err != nil {
t.Errorf("Could not match the UUID format, err: %+v, match: %+v", err, match)
}
}
func TestFakeHyphenated(t *testing.T) {
uuid := UUIDHyphenated()
exp := "[a-zA-Z 0-9]"
pattern := fmt.Sprintf("^%s{8}-%s{4}-%s{4}-%s{4}-%s{12}$", exp, exp, exp, exp, exp)
if match, err := regexp.Match(pattern, []byte(uuid)); !match || err != nil {
t.Errorf("Could not match the UUID hyphenated format, err: %+v, match: %+v", err, match)
}
}