-
Notifications
You must be signed in to change notification settings - Fork 28
/
service_user_test.go
63 lines (59 loc) · 1.33 KB
/
service_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
package aiven
import (
"bytes"
"encoding/json"
"reflect"
"testing"
)
// TestAccessControlMarshalJSON test AccessControl JSON marshalling process
func TestAccessControlMarshalJSON(t *testing.T) {
strPtr := func(s string) *string {
return &s
}
type notEmpty struct {
M3Group string `json:"m3_group"`
RedisACLKeys []string `json:"redis_acl_keys"`
}
tests := []struct {
name string
input *AccessControl
wantType interface{}
want interface{}
}{
{
name: "empty",
input: &AccessControl{},
wantType: &map[string]interface{}{},
want: &map[string]interface{}{},
},
{
name: "notempty",
input: &AccessControl{
M3Group: strPtr("foo"),
RedisACLKeys: []string{"bar"},
},
wantType: ¬Empty{},
want: ¬Empty{
M3Group: "foo",
RedisACLKeys: []string{"bar"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b, err := json.Marshal(tt.input)
if err != nil {
t.Errorf("MarshalJSON() error = %v", err)
return
}
dec := json.NewDecoder(bytes.NewReader(b))
dec.DisallowUnknownFields()
if err := dec.Decode(tt.wantType); err != nil {
t.Errorf("Decode() error = %v", err)
}
if !reflect.DeepEqual(tt.wantType, tt.want) {
t.Errorf("DeepEqual() got = %+v, want = %+v", tt.wantType, tt.want)
}
})
}
}