Skip to content

Commit 85b5d89

Browse files
committed
pass the right testing context
1 parent ee38748 commit 85b5d89

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

internal/actions/drain_node_handler_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
246246
podFailedDeletionErr := &podFailedActionError{}
247247
t.Parallel()
248248
type fields struct {
249-
clientSet func() *fake.Clientset
249+
clientSet func(t *testing.T) *fake.Clientset
250250
}
251251
type args struct {
252252
action *castai.ClusterAction
@@ -265,7 +265,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
265265
name: "nil",
266266
args: args{},
267267
fields: fields{
268-
clientSet: func() *fake.Clientset {
268+
clientSet: func(t *testing.T) *fake.Clientset {
269269
return fake.NewClientset()
270270
},
271271
},
@@ -279,7 +279,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
279279
},
280280
},
281281
fields: fields{
282-
clientSet: func() *fake.Clientset {
282+
clientSet: func(t *testing.T) *fake.Clientset {
283283
return fake.NewClientset()
284284
},
285285
},
@@ -291,7 +291,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
291291
action: newActionDrainNode("", nodeID, providerID, 1, true),
292292
},
293293
fields: fields{
294-
clientSet: func() *fake.Clientset {
294+
clientSet: func(t *testing.T) *fake.Clientset {
295295
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
296296
},
297297
},
@@ -304,7 +304,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
304304
nil, nil, nil, nil, nil),
305305
},
306306
fields: fields{
307-
clientSet: func() *fake.Clientset {
307+
clientSet: func(t *testing.T) *fake.Clientset {
308308
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
309309
},
310310
},
@@ -313,7 +313,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
313313
{
314314
name: "action with another node id and provider id - skip drain",
315315
fields: fields{
316-
clientSet: func() *fake.Clientset {
316+
clientSet: func(t *testing.T) *fake.Clientset {
317317
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
318318
},
319319
},
@@ -325,7 +325,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
325325
{
326326
name: "action with proper node id and another provider id - skip drain",
327327
fields: fields{
328-
clientSet: func() *fake.Clientset {
328+
clientSet: func(t *testing.T) *fake.Clientset {
329329
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
330330
},
331331
},
@@ -337,7 +337,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
337337
{
338338
name: "action with another node id and proper provider id - skip drain",
339339
fields: fields{
340-
clientSet: func() *fake.Clientset {
340+
clientSet: func(t *testing.T) *fake.Clientset {
341341
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
342342
},
343343
},
@@ -349,7 +349,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
349349
{
350350
name: "drain node successfully",
351351
fields: fields{
352-
clientSet: func() *fake.Clientset {
352+
clientSet: func(t *testing.T) *fake.Clientset {
353353
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
354354
prependEvictionReaction(t, c, true, false)
355355
return c
@@ -364,7 +364,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
364364
{
365365
name: "skip drain when node not found",
366366
fields: fields{
367-
clientSet: func() *fake.Clientset {
367+
clientSet: func(t *testing.T) *fake.Clientset {
368368
return setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
369369
},
370370
},
@@ -376,7 +376,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
376376
{
377377
name: "when eviction fails for a pod and force=false, leaves node cordoned and skip deletion",
378378
fields: fields{
379-
clientSet: func() *fake.Clientset {
379+
clientSet: func(t *testing.T) *fake.Clientset {
380380
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
381381
prependEvictionReaction(t, c, false, false)
382382
return c
@@ -392,7 +392,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
392392
{
393393
name: "when eviction timeout is reached and force=false, leaves node cordoned and skip deletion",
394394
fields: fields{
395-
clientSet: func() *fake.Clientset {
395+
clientSet: func(t *testing.T) *fake.Clientset {
396396
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
397397
prependEvictionReaction(t, c, false, true)
398398
return c
@@ -408,7 +408,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
408408
{
409409
name: "eviction fails and force=true, force remove pods: timeout during eviction",
410410
fields: fields{
411-
clientSet: func() *fake.Clientset {
411+
clientSet: func(*testing.T) *fake.Clientset {
412412
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
413413
prependEvictionReaction(t, c, false, true)
414414
actualCalls := 0
@@ -446,7 +446,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
446446
{
447447
name: "eviction fails and force=true, force remove pods: failed pod during eviction",
448448
fields: fields{
449-
clientSet: func() *fake.Clientset {
449+
clientSet: func(t *testing.T) *fake.Clientset {
450450
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
451451
prependEvictionReaction(t, c, false, false)
452452
actualCalls := 0
@@ -484,7 +484,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
484484
{
485485
name: "eviction fails and force=true, at least one pod fails to delete due to internal error, should return error",
486486
fields: fields{
487-
clientSet: func() *fake.Clientset {
487+
clientSet: func(t *testing.T) *fake.Clientset {
488488
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
489489
c.PrependReactor("delete", "pods", func(action ktest.Action) (handled bool, ret runtime.Object, err error) {
490490
deleteAction := action.(ktest.DeleteActionImpl)
@@ -512,7 +512,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
512512
{
513513
name: "eviction fails and force=true, timeout during deletion should be retried and returned",
514514
fields: fields{
515-
clientSet: func() *fake.Clientset {
515+
clientSet: func(t *testing.T) *fake.Clientset {
516516
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
517517
actualDeleteCalls := 0
518518
c.PrependReactor("delete", "pods", func(action ktest.Action) (handled bool, ret runtime.Object, err error) {
@@ -541,7 +541,7 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
541541
{
542542
name: "force=true, failed eviction for PDBs should be retried until timeout before deleting",
543543
fields: fields{
544-
clientSet: func() *fake.Clientset {
544+
clientSet: func(t *testing.T) *fake.Clientset {
545545
c := setupFakeClientWithNodePodEviction(nodeName, nodeID, providerID, podName)
546546
c.PrependReactor("create", "pods", func(action ktest.Action) (handled bool, ret runtime.Object, err error) {
547547
if action.GetSubresource() != "eviction" {
@@ -574,12 +574,11 @@ func TestDrainNodeHandler_Handle(t *testing.T) {
574574
},
575575
}
576576
for _, tt := range tests {
577-
tt := tt
578577
t.Run(tt.name, func(t *testing.T) {
579578
t.Parallel()
580579
h := &DrainNodeHandler{
581580
log: logrus.New(),
582-
clientset: tt.fields.clientSet(),
581+
clientset: tt.fields.clientSet(t),
583582
cfg: tt.args.cfg,
584583
}
585584
err := h.Handle(context.Background(), tt.args.action)

0 commit comments

Comments
 (0)