-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs_test.go
189 lines (182 loc) · 2.98 KB
/
structs_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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package structs
import (
"reflect"
"testing"
)
type (
Case1 struct{}
Case2 struct{}
Case3 struct{}
Case4 struct{}
Case5 interface{}
)
type Example1 struct {
Case1 *Case1
Case2 *Case2
Case3 *Case3
Case4 *Case4
}
type Example2 struct {
Case1 *Case1
Case2 *Case2
Case3 *Case3
Case4 *Case4
*Example1
}
type Example3 struct {
Interface Case5
Example2
}
func TestGetNilFields(t *testing.T) {
type args struct {
value interface{}
}
tests := []struct {
args args
want []string
}{
{
args: args{
value: new(Example1),
},
want: []string{
"Example1.Case1",
"Example1.Case2",
"Example1.Case3",
"Example1.Case4",
},
},
{
args: args{
value: Example1{
Case2: new(Case2),
},
},
want: []string{
"Example1.Case1",
"Example1.Case3",
"Example1.Case4",
},
},
{
args: args{
value: Example2{
Case1: new(Case1),
Case2: new(Case2),
Case3: new(Case3),
Case4: new(Case4),
},
},
want: []string{
"Example2.Example1",
},
},
{
args: args{
value: &Example2{
Case1: new(Case1),
Case2: new(Case2),
Case3: new(Case3),
Case4: new(Case4),
Example1: new(Example1),
},
},
want: []string{
"Example2.Example1.Case1",
"Example2.Example1.Case2",
"Example2.Example1.Case3",
"Example2.Example1.Case4",
},
},
{
args: args{
value: Example2{
Case1: new(Case1),
Case2: new(Case2),
Case3: new(Case3),
Case4: new(Case4),
Example1: &Example1{
Case2: new(Case2),
},
},
},
want: []string{
"Example2.Example1.Case1",
"Example2.Example1.Case3",
"Example2.Example1.Case4",
},
},
{
args: args{
value: Example3{
Example2: Example2{
Case2: new(Case2),
},
},
},
want: []string{
"Example3.Interface",
"Example3.Example2.Case1",
"Example3.Example2.Case3",
"Example3.Example2.Case4",
"Example3.Example2.Example1",
},
},
{
args: args{
value: new(Example3),
},
want: []string{
"Example3.Interface",
"Example3.Example2.Case1",
"Example3.Example2.Case2",
"Example3.Example2.Case3",
"Example3.Example2.Case4",
"Example3.Example2.Example1",
},
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
if got := GetNilFields(tt.args.value); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetNilFields() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetStructName(t *testing.T) {
var testStruct struct{}
type args struct {
obj any
}
tests := []struct {
args args
want string
}{
{
args: args{
obj: Example1{},
},
want: "Example1",
},
{
args: args{
obj: Case1{},
},
want: "Case1",
},
{
args: args{
obj: testStruct,
},
want: "",
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
if got := GetStructName(tt.args.obj); got != tt.want {
t.Errorf("GetStructName() = %v, want %v", got, tt.want)
}
})
}
}