forked from kai-ten/go-csf-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
66 lines (57 loc) · 1.38 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
62
63
64
65
66
package gcs
import "testing"
func TestValidUserObject(t *testing.T) {
user := &User{
AccountType: "test",
AccountTypeID: 2,
AccountUID: "123",
Domain: "Active Directory",
EmailAddress: "[email protected]",
Groups: nil,
Name: "name",
OrgID: "345",
Type: "AD User",
TypeID: 1,
UniqueUserID: "456",
UserCredentialID: "",
UserID: "456",
}
user, err := ValidateUser(user)
if err != nil {
t.Fatalf("User should have been valid: %v", err)
}
t.Logf("User email: %v", user.EmailAddress)
}
func TestInvalidUserEmail(t *testing.T) {
user := &User{
EmailAddress: "invalid",
}
user, err := ValidateUser(user)
if err == nil {
t.Fatalf("User validation should have failed: %v", user.EmailAddress)
}
}
func BenchmarkValidUserObject(b *testing.B) {
b.ReportAllocs()
user := &User{
AccountType: "test",
AccountTypeID: 2,
AccountUID: "123",
Domain: "Active Directory",
EmailAddress: "[email protected]",
Groups: nil,
Name: "name",
OrgID: "345",
Type: "AD User",
TypeID: 1,
UniqueUserID: "456",
UserCredentialID: "",
UserID: "456",
}
for n := 0; n < b.N; n++ {
_, err := ValidateUser(user)
if err != nil {
b.Fatalf("User object is invalid: %v", err)
}
}
}