-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_test.go
106 lines (100 loc) · 2.31 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package xrhidgen
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
func TestNewUser(t *testing.T) {
type Tests struct {
description string
seed int64
input User
want *identity.User
wantError error
}
tests := []Tests{
{
description: "empty template",
seed: 100,
input: User{},
want: &identity.User{
Email: "[email protected]",
FirstName: "Augustine",
Active: true,
Internal: false,
OrgAdmin: false,
LastName: "Stracke",
Locale: "fo",
UserID: "salify",
Username: "platas",
},
},
{
description: "partial template",
seed: 100,
input: User{
Email: pointy.String("[email protected]"),
FirstName: pointy.String("John"),
LastName: pointy.String("Smith"),
},
want: &identity.User{
Email: "[email protected]",
FirstName: "John",
Active: false,
Internal: true,
OrgAdmin: true,
LastName: "Smith",
Locale: "ik",
UserID: "goniometer",
Username: "waldner",
},
},
{
description: "full template",
seed: 100,
input: User{
Email: pointy.String("[email protected]"),
FirstName: pointy.String("John"),
IsActive: pointy.Bool(true),
IsInternal: pointy.Bool(true),
IsOrgAdmin: pointy.Bool(false),
LastName: pointy.String("Smith"),
Locale: pointy.String("en"),
UserID: pointy.String("jsmith1"),
Username: pointy.String("jsm"),
},
want: &identity.User{
Email: "[email protected]",
FirstName: "John",
Active: true,
Internal: true,
OrgAdmin: false,
LastName: "Smith",
Locale: "en",
UserID: "jsmith1",
Username: "jsm",
},
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
faker.SetSeed(test.seed)
got, err := NewUser(test.input)
if test.wantError != nil {
if !cmp.Equal(err, test.wantError, cmpopts.EquateErrors()) {
t.Errorf("%#v != %#v", err, test.wantError)
}
} else {
if err != nil {
t.Fatal(err)
}
if !cmp.Equal(got, test.want) {
t.Errorf("%v", cmp.Diff(got, test.want))
}
}
})
}
}