@@ -25,7 +25,6 @@ import (
25
25
26
26
"k8s.io/apimachinery/pkg/api/operation"
27
27
"k8s.io/apimachinery/pkg/util/validation/field"
28
- "k8s.io/utils/ptr"
29
28
)
30
29
31
30
type TestStruct struct {
@@ -102,107 +101,6 @@ func testEachSliceValUpdate[T any](t *testing.T, name string, input []T) {
102
101
})
103
102
}
104
103
105
- func TestEachSliceValNilablePointer (t * testing.T ) {
106
- testEachSliceValNilable (t , "valid" , []* int {ptr .To (11 ), ptr .To (12 ), ptr .To (13 )})
107
- testEachSliceValNilable (t , "valid" , []* string {ptr .To ("a" ), ptr .To ("b" ), ptr .To ("c" )})
108
- testEachSliceValNilable (t , "valid" , []* TestStruct {{11 , "a" }, {12 , "b" }, {13 , "c" }})
109
-
110
- testEachSliceValNilable (t , "empty" , []* int {})
111
- testEachSliceValNilable (t , "empty" , []* string {})
112
- testEachSliceValNilable (t , "empty" , []* TestStruct {})
113
-
114
- testEachSliceValNilable [int ](t , "nil" , nil )
115
- testEachSliceValNilable [string ](t , "nil" , nil )
116
- testEachSliceValNilable [TestStruct ](t , "nil" , nil )
117
-
118
- testEachSliceValNilableUpdate (t , "valid" , []* int {ptr .To (11 ), ptr .To (12 ), ptr .To (13 )})
119
- testEachSliceValNilableUpdate (t , "valid" , []* string {ptr .To ("a" ), ptr .To ("b" ), ptr .To ("c" )})
120
- testEachSliceValNilableUpdate (t , "valid" , []* TestStruct {{11 , "a" }, {12 , "b" }, {13 , "c" }})
121
-
122
- testEachSliceValNilableUpdate (t , "empty" , []* int {})
123
- testEachSliceValNilableUpdate (t , "empty" , []* string {})
124
- testEachSliceValNilableUpdate (t , "empty" , []* TestStruct {})
125
-
126
- testEachSliceValNilableUpdate [int ](t , "nil" , nil )
127
- testEachSliceValNilableUpdate [string ](t , "nil" , nil )
128
- testEachSliceValNilableUpdate [TestStruct ](t , "nil" , nil )
129
- }
130
-
131
- func TestEachSliceValNilableSlice (t * testing.T ) {
132
- testEachSliceValNilable (t , "valid" , [][]int {{11 , 12 , 13 }, {12 , 13 , 14 }, {13 , 14 , 15 }})
133
- testEachSliceValNilable (t , "valid" , [][]string {{"a" , "b" , "c" }, {"b" , "c" , "d" }, {"c" , "d" , "e" }})
134
- testEachSliceValNilable (t , "valid" , [][]TestStruct {
135
- {{11 , "a" }, {12 , "b" }, {13 , "c" }},
136
- {{12 , "a" }, {13 , "b" }, {14 , "c" }},
137
- {{13 , "a" }, {14 , "b" }, {15 , "c" }}})
138
-
139
- testEachSliceValNilable (t , "empty" , [][]int {{}, {}, {}})
140
- testEachSliceValNilable (t , "empty" , [][]string {{}, {}, {}})
141
- testEachSliceValNilable (t , "empty" , [][]TestStruct {{}, {}, {}})
142
-
143
- testEachSliceValNilable [int ](t , "nil" , nil )
144
- testEachSliceValNilable [string ](t , "nil" , nil )
145
- testEachSliceValNilable [TestStruct ](t , "nil" , nil )
146
-
147
- testEachSliceValNilableUpdate (t , "valid" , [][]int {{11 , 12 , 13 }, {12 , 13 , 14 }, {13 , 14 , 15 }})
148
- testEachSliceValNilableUpdate (t , "valid" , [][]string {{"a" , "b" , "c" }, {"b" , "c" , "d" }, {"c" , "d" , "e" }})
149
- testEachSliceValNilableUpdate (t , "valid" , [][]TestStruct {
150
- {{11 , "a" }, {12 , "b" }, {13 , "c" }},
151
- {{12 , "a" }, {13 , "b" }, {14 , "c" }},
152
- {{13 , "a" }, {14 , "b" }, {15 , "c" }}})
153
-
154
- testEachSliceValNilableUpdate (t , "empty" , [][]int {{}, {}, {}})
155
- testEachSliceValNilableUpdate (t , "empty" , [][]string {{}, {}, {}})
156
- testEachSliceValNilableUpdate (t , "empty" , [][]TestStruct {{}, {}, {}})
157
-
158
- testEachSliceValNilableUpdate [int ](t , "nil" , nil )
159
- testEachSliceValNilableUpdate [string ](t , "nil" , nil )
160
- testEachSliceValNilableUpdate [TestStruct ](t , "nil" , nil )
161
- }
162
-
163
- func testEachSliceValNilable [T any ](t * testing.T , name string , input []T ) {
164
- var zero T
165
- t .Run (fmt .Sprintf ("%s(%T)" , name , zero ), func (t * testing.T ) {
166
- calls := 0
167
- vfn := func (ctx context.Context , op operation.Operation , fldPath * field.Path , newVal , oldVal T ) field.ErrorList {
168
- if ! reflect .DeepEqual (oldVal , zero ) {
169
- t .Errorf ("expected nil oldVal, got %v" , oldVal )
170
- }
171
- calls ++
172
- return nil
173
- }
174
- _ = EachSliceValNilable (context .Background (), operation.Operation {}, field .NewPath ("test" ), input , nil , nil , vfn )
175
- if calls != len (input ) {
176
- t .Errorf ("expected %d calls, got %d" , len (input ), calls )
177
- }
178
- })
179
- }
180
-
181
- func testEachSliceValNilableUpdate [T any ](t * testing.T , name string , input []T ) {
182
- var zero T
183
- t .Run (fmt .Sprintf ("%s(%T)" , name , zero ), func (t * testing.T ) {
184
- calls := 0
185
- vfn := func (ctx context.Context , op operation.Operation , fldPath * field.Path , newVal , oldVal T ) field.ErrorList {
186
- if reflect .DeepEqual (oldVal , zero ) {
187
- t .Fatalf ("expected non-nil oldVal" )
188
- }
189
- if ! reflect .DeepEqual (newVal , oldVal ) {
190
- t .Errorf ("expected oldVal == newVal, got %v, %v" , oldVal , newVal )
191
- }
192
- calls ++
193
- return nil
194
- }
195
- old := make ([]T , len (input ))
196
- copy (old , input )
197
- slices .Reverse (old )
198
- cmp := func (a , b T ) bool { return reflect .DeepEqual (a , b ) }
199
- _ = EachSliceValNilable (context .Background (), operation.Operation {}, field .NewPath ("test" ), input , old , cmp , vfn )
200
- if calls != len (input ) {
201
- t .Errorf ("expected %d calls, got %d" , len (input ), calls )
202
- }
203
- })
204
- }
205
-
206
104
func TestEachMapVal (t * testing.T ) {
207
105
testEachMapVal (t , "valid" , map [string ]int {"one" : 11 , "two" : 12 , "three" : 13 })
208
106
testEachMapVal (t , "valid" , map [string ]string {"A" : "a" , "B" : "b" , "C" : "c" })
@@ -235,61 +133,6 @@ func testEachMapVal[T any](t *testing.T, name string, input map[string]T) {
235
133
})
236
134
}
237
135
238
- func TestEachMapValNilablePointer (t * testing.T ) {
239
- testEachMapValNilable (t , "valid" , map [string ]* int {"one" : ptr .To (11 ), "two" : ptr .To (12 ), "three" : ptr .To (13 )})
240
- testEachMapValNilable (t , "valid" , map [string ]* string {"A" : ptr .To ("a" ), "B" : ptr .To ("b" ), "C" : ptr .To ("c" )})
241
- testEachMapValNilable (t , "valid" , map [string ]* TestStruct {"one" : {11 , "a" }, "two" : {12 , "b" }, "three" : {13 , "c" }})
242
-
243
- testEachMapValNilable (t , "empty" , map [string ]* int {})
244
- testEachMapValNilable (t , "empty" , map [string ]* string {})
245
- testEachMapValNilable (t , "empty" , map [string ]* TestStruct {})
246
-
247
- testEachMapValNilable [int ](t , "nil" , nil )
248
- testEachMapValNilable [string ](t , "nil" , nil )
249
- testEachMapValNilable [TestStruct ](t , "nil" , nil )
250
- }
251
-
252
- func TestEachMapValNilableSlice (t * testing.T ) {
253
- testEachMapValNilable (t , "valid" , map [string ][]int {
254
- "one" : {11 , 12 , 13 },
255
- "two" : {12 , 13 , 14 },
256
- "three" : {13 , 14 , 15 }})
257
- testEachMapValNilable (t , "valid" , map [string ][]string {
258
- "A" : {"a" , "b" , "c" },
259
- "B" : {"b" , "c" , "d" },
260
- "C" : {"c" , "d" , "e" }})
261
- testEachMapValNilable (t , "valid" , map [string ][]TestStruct {
262
- "one" : {{11 , "a" }, {12 , "b" }, {13 , "c" }},
263
- "two" : {{12 , "a" }, {13 , "b" }, {14 , "c" }},
264
- "three" : {{13 , "a" }, {14 , "b" }, {15 , "c" }}})
265
-
266
- testEachMapValNilable (t , "empty" , map [string ][]int {"a" : {}, "b" : {}, "c" : {}})
267
- testEachMapValNilable (t , "empty" , map [string ][]string {"a" : {}, "b" : {}, "c" : {}})
268
- testEachMapValNilable (t , "empty" , map [string ][]TestStruct {"a" : {}, "b" : {}, "c" : {}})
269
-
270
- testEachMapValNilable [int ](t , "nil" , nil )
271
- testEachMapValNilable [string ](t , "nil" , nil )
272
- testEachMapValNilable [TestStruct ](t , "nil" , nil )
273
- }
274
-
275
- func testEachMapValNilable [T any ](t * testing.T , name string , input map [string ]T ) {
276
- var zero T
277
- t .Run (fmt .Sprintf ("%s(%T)" , name , zero ), func (t * testing.T ) {
278
- calls := 0
279
- vfn := func (ctx context.Context , op operation.Operation , fldPath * field.Path , newVal , oldVal T ) field.ErrorList {
280
- if ! reflect .DeepEqual (oldVal , zero ) {
281
- t .Errorf ("expected nil oldVal, got %v" , oldVal )
282
- }
283
- calls ++
284
- return nil
285
- }
286
- _ = EachMapValNilable (context .Background (), operation.Operation {}, field .NewPath ("test" ), input , nil , vfn )
287
- if calls != len (input ) {
288
- t .Errorf ("expected %d calls, got %d" , len (input ), calls )
289
- }
290
- })
291
- }
292
-
293
136
type StringType string
294
137
295
138
func TestEachMapKey (t * testing.T ) {
0 commit comments