Skip to content

Commit 8e6ed1e

Browse files
committed
update the node controler unit test
1 parent 4c5ecb3 commit 8e6ed1e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

pkg/operator/staticpod/controller/node/node_controller_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ func validateJSONPatch(expected, actual *jsonpatch.PatchSet) error {
8282

8383
func TestNodeControllerDegradedConditionType(t *testing.T) {
8484
scenarios := []struct {
85-
name string
86-
masterNodes []runtime.Object
87-
existingNodeStatuses []operatorv1.NodeStatus
88-
existingConditions []operatorv1.OperatorCondition
89-
triggerStatusApplyError error
85+
name string
86+
masterNodes []runtime.Object
87+
existingNodeStatuses []operatorv1.NodeStatus
88+
existingConditions []operatorv1.OperatorCondition
89+
triggerStatusApplyErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
9090

9191
verifyNodeStatus func([]operatorv1.OperatorCondition) error
9292
verifyJSONPatch func(*jsonpatch.PatchSet) error
@@ -197,7 +197,16 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
197197
NodeName: "test-node-4",
198198
},
199199
},
200-
triggerStatusApplyError: fmt.Errorf("nasty err"),
200+
triggerStatusApplyErrorFn: func() func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
201+
var counter int
202+
return func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
203+
if counter == 0 {
204+
counter++
205+
return fmt.Errorf("nasty err")
206+
}
207+
return nil
208+
}
209+
}(),
201210
verifyNodeStatus: func(conditions []operatorv1.OperatorCondition) error {
202211
var expectedCondition operatorv1.OperatorCondition
203212
expectedCondition.Type = condition.NodeControllerDegradedConditionType
@@ -442,11 +451,9 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
442451
kubeClient := fake.NewSimpleClientset(scenario.masterNodes...)
443452
fakeLister := v1helpers.NewFakeNodeLister(kubeClient)
444453

445-
var triggerStatusUpdateError func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
446-
if scenario.triggerStatusApplyError != nil {
447-
triggerStatusUpdateError = func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
448-
return scenario.triggerStatusApplyError
449-
}
454+
var triggerStatusUpdateErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
455+
if scenario.triggerStatusApplyErrorFn != nil {
456+
triggerStatusUpdateErrorFn = scenario.triggerStatusApplyErrorFn
450457
}
451458
fakeStaticPodOperatorClient := v1helpers.NewFakeStaticPodOperatorClient(
452459
&operatorv1.StaticPodOperatorSpec{
@@ -461,7 +468,7 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
461468
},
462469
NodeStatuses: scenario.existingNodeStatuses,
463470
},
464-
triggerStatusUpdateError,
471+
triggerStatusUpdateErrorFn,
465472
nil,
466473
)
467474

0 commit comments

Comments
 (0)