@@ -26,6 +26,7 @@ import (
26
26
"k8s.io/api/discovery/v1beta1"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
28
"k8s.io/apimachinery/pkg/runtime"
29
+ ktypes "k8s.io/apimachinery/pkg/types"
29
30
ctrl "sigs.k8s.io/controller-runtime"
30
31
"sigs.k8s.io/controller-runtime/pkg/client"
31
32
fakecli "sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -213,3 +214,66 @@ func TestEpSliceDeletePredicate(t *testing.T) {
213
214
}
214
215
}
215
216
}
217
+
218
+ func TestReconcile (t * testing.T ) {
219
+ a := assert .New (t )
220
+ cases := []struct {
221
+ dataActions map [string ]* epsData
222
+ srvCounts map [string ]map [string ]int
223
+ expRes ctrl.Result
224
+ expErr error
225
+ expSrvCounts map [string ]map [string ]int
226
+ }{
227
+ {},
228
+ {
229
+ dataActions : map [string ]* epsData {
230
+ "ns-name/name" : {
231
+ count : 3 ,
232
+ srv : "srv" ,
233
+ },
234
+ },
235
+ srvCounts : map [string ]map [string ]int {
236
+ "ns-name/srv" : {
237
+ "another-name" : 5 ,
238
+ },
239
+ },
240
+ expSrvCounts : map [string ]map [string ]int {
241
+ "ns-name/srv" : {
242
+ "another-name" : 5 ,
243
+ "name" : 3 ,
244
+ },
245
+ },
246
+ },
247
+ {
248
+ dataActions : map [string ]* epsData {
249
+ "ns-name/name" : {
250
+ count : 3 ,
251
+ srv : "srv" ,
252
+ },
253
+ },
254
+ srvCounts : map [string ]map [string ]int {},
255
+ expSrvCounts : map [string ]map [string ]int {
256
+ "ns-name/srv" : {
257
+ "name" : 3 ,
258
+ },
259
+ },
260
+ },
261
+ }
262
+ failed := func (i int ) {
263
+ a .FailNow (fmt .Sprintf ("case %d failed" , i ))
264
+ }
265
+ for i , currCase := range cases {
266
+ eps := & EndpointSliceReconciler {
267
+ BaseReconciler : & BaseReconciler {
268
+ Log : ctrl .Log .WithName ("controllers" ),
269
+ },
270
+ epsDataActions : currCase .dataActions ,
271
+ srvCounts : currCase .srvCounts ,
272
+ }
273
+
274
+ res , err := eps .Reconcile (ctrl.Request {NamespacedName : ktypes.NamespacedName {Namespace : "ns-name" , Name : "name" }})
275
+ if ! a .Equal (currCase .expRes , res ) || ! a .Equal (currCase .expErr , err ) || ! a .Equal (currCase .expSrvCounts , eps .srvCounts ) {
276
+ failed (i )
277
+ }
278
+ }
279
+ }
0 commit comments