-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_test.go
61 lines (53 loc) · 1.29 KB
/
user_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
package genesis_test
import (
"regexp"
"testing"
domain "github.com/adrianolmedo/genesis"
)
func TestCheckEmptyFields(t *testing.T) {
tt := []struct {
name string
user domain.User
errExpected bool
}{
{
name: "empty-struct",
user: domain.User{},
errExpected: true,
},
{
name: "empty-fields",
user: domain.User{FirstName: "", LastName: "", Email: "", Password: ""},
errExpected: true,
},
{
name: "filled-fields",
user: domain.User{
FirstName: "Adrián",
LastName: "Olmedo",
Email: "aol.ve@aol.com",
Password: "1234567@"},
errExpected: false,
},
}
for _, tc := range tt {
err := tc.user.Validate()
errReceived := err != nil
if errReceived != tc.errExpected {
t.Fatalf("%s: validateUser: unexpected error status: %v", tc.name, err)
}
}
}
// TestNextUUID se segura que el campo UUID tenga un valor UUID válido.
func TestNextUUID(t *testing.T) {
uuid := domain.NextUUID()
if !isValidUUID(uuid) {
t.Errorf("NextUUID() generate invalid UUID: %s", uuid)
} else {
t.Logf("%s: valid! ", uuid)
}
}
func isValidUUID(uuid string) bool {
r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
return r.MatchString(uuid)
}