-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes_test.go
143 lines (131 loc) · 2.64 KB
/
types_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package common
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestString(t *testing.T) {
testliteral := "literal"
var i interface{} = String(testliteral)
assert.Equal(t, reflect.Ptr, reflect.ValueOf(i).Kind())
assert.Equal(t, &testliteral, i)
}
func TestStringValue(t *testing.T) {
testliteral := "literal"
teststrptr := &testliteral
var sv interface{} = StringValue(teststrptr)
assert.Equal(t, reflect.String, reflect.ValueOf(sv).Kind())
assert.Equal(t, testliteral, sv)
assert.Equal(t, "", StringValue((*string)(nil)))
}
func TestInt64(t *testing.T) {
var testint int64 = 7
testintptr := Int64(testint)
assert.Equal(t, reflect.Ptr, reflect.ValueOf(testintptr).Kind())
assert.Equal(t, &testint, testintptr)
}
func TestUintValue(t *testing.T) {
var testUintValue uint = 7
testUintPtr := &testUintValue
var uiv interface{} = UintValue(testUintPtr)
assert.Equal(t, reflect.Uint, reflect.ValueOf(uiv).Kind())
assert.Equal(t, testUintValue, uiv)
assert.Equal(t, uint(0), UintValue((*uint)(nil)))
}
func TestStringToBool(t *testing.T) {
testcases := []struct {
teststring string
pass bool
}{
{
teststring: "true",
pass: true,
},
{
teststring: "True",
pass: true,
},
{
teststring: "t",
pass: true,
},
{
teststring: "yEs",
pass: true,
},
{
teststring: "Y",
pass: true,
},
{
teststring: "on",
pass: true,
},
{
teststring: "tr",
pass: false,
},
{
teststring: "nil",
pass: false,
},
{
teststring: "false",
pass: false,
},
{
teststring: "FOOBAR",
pass: false,
},
}
for _, testcase := range testcases {
assert.Equal(t, testcase.pass, StringToBool(testcase.teststring))
}
}
func TestStringEmpty(t *testing.T) {
assert.True(t, StringEmpty(""))
assert.False(t, StringEmpty("NONEMPTY"))
}
func TestMakeSub(t *testing.T) {
type testCase struct {
name string
User *User
Sub string
}
testcases := []testCase{
{
name: "empty",
User: nil,
Sub: "",
},
{
name: "human user with email",
User: &User{
Email: String("[email protected]"),
},
Sub: "email:[email protected]",
},
{
name: "machine user with email",
User: &User{
Email: String("my-machine-user@oauth2"),
},
Sub: "m2m:my-machine-user",
},
{
name: "human user with email internal claim",
User: &User{
Email: String("my-machine-user@oauth2"),
Internal: &Internal{
EmployeeID: "X123456",
},
},
Sub: "eid:x123456",
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.Sub, tc.User.MakeSub())
})
}
}