@@ -82,11 +82,11 @@ func validateJSONPatch(expected, actual *jsonpatch.PatchSet) error {
8282
8383func 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