-
Notifications
You must be signed in to change notification settings - Fork 284
/
utils_test.go
139 lines (115 loc) · 2.54 KB
/
utils_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
package gocloak_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/Nerzal/gocloak/v13"
)
func TestStringP(t *testing.T) {
p := gocloak.StringP("test value")
assert.Equal(t, "test value", *p)
}
func TestPString(t *testing.T) {
p := "test value"
v := gocloak.PString(&p)
assert.Equal(t, p, v)
}
func TestPStringNil(t *testing.T) {
v := gocloak.PString(nil)
assert.Equal(t, "", v)
}
func TestBoolP(t *testing.T) {
p1 := gocloak.BoolP(false)
assert.False(t, *p1)
p2 := gocloak.BoolP(false)
assert.False(t, *p1)
assert.False(t, p1 == p2)
p := gocloak.BoolP(true)
assert.True(t, *p)
}
func TestPBool(t *testing.T) {
p := true
v := gocloak.PBool(&p)
assert.True(t, v)
p = false
v = gocloak.PBool(&p)
assert.False(t, v)
v = gocloak.PBool(nil)
assert.False(t, v)
}
func TestIntP(t *testing.T) {
p := gocloak.IntP(42)
assert.Equal(t, 42, *p)
}
func TestInt32P(t *testing.T) {
v := int32(42)
p := gocloak.Int32P(v)
assert.Equal(t, v, *p)
}
func TestInt64P(t *testing.T) {
v := int64(42)
p := gocloak.Int64P(v)
assert.Equal(t, v, *p)
}
func TestPInt(t *testing.T) {
p := 42
v := gocloak.PInt(&p)
assert.Equal(t, p, v)
assert.IsType(t, p, v)
v = gocloak.PInt(nil)
assert.Equal(t, int(0), v)
assert.IsType(t, int(0), v)
}
func TestPInt32(t *testing.T) {
var p int32 = 42
v := gocloak.PInt32(&p)
assert.Equal(t, p, v)
assert.IsType(t, p, v)
v = gocloak.PInt32(nil)
assert.Equal(t, int32(0), v)
assert.IsType(t, int32(0), v)
}
func TestPInt64(t *testing.T) {
var p int64 = 42
v := gocloak.PInt64(&p)
assert.Equal(t, p, v)
assert.IsType(t, p, v)
v = gocloak.PInt64(nil)
assert.Equal(t, int64(0), v)
assert.IsType(t, int64(0), v)
}
func TestFloat32P(t *testing.T) {
v := float32(42.42)
p := gocloak.Float32P(v)
assert.Equal(t, v, *p)
}
func TestFloat64P(t *testing.T) {
v := 42.42
p := gocloak.Float64P(v)
assert.Equal(t, v, *p)
}
func TestPFloat32(t *testing.T) {
var p float32 = 42.42
v := gocloak.PFloat32(&p)
assert.Equal(t, p, v)
assert.IsType(t, p, v)
v = gocloak.PFloat32(nil)
assert.Equal(t, float32(0), v)
assert.IsType(t, float32(0), v)
}
func TestPFloat64(t *testing.T) {
p := 42.42
v := gocloak.PFloat64(&p)
assert.Equal(t, p, v)
assert.IsType(t, p, v)
v = gocloak.PFloat64(nil)
assert.Equal(t, float64(0), v)
assert.IsType(t, float64(0), v)
}
func TestNilOrEmptyArray(t *testing.T) {
a := gocloak.NilOrEmptyArray(&[]string{"c", "d"})
b := gocloak.NilOrEmptyArray(&[]string{"", "b"})
c := gocloak.NilOrEmptyArray(&[]string{})
assert.False(t, a)
assert.True(t, b)
assert.True(t, c)
}