|
| 1 | +package eventhandlers |
| 2 | + |
| 3 | +import ( |
| 4 | +"github.com/stretchr/testify/assert" |
| 5 | +corev1 "k8s.io/api/core/v1" |
| 6 | +"testing" |
| 7 | +) |
| 8 | + |
| 9 | +func Test_enqueueRequestsForNodeEvent_shouldEnqueueTGBDueToNodeEvent(t *testing.T) { |
| 10 | +type args struct { |
| 11 | +nodeOldSuitableAsTrafficProxyForTGB bool |
| 12 | +nodeOldReadyCondStatus corev1.ConditionStatus |
| 13 | +nodeNewSuitableAsTrafficProxyForTGB bool |
| 14 | +nodeNewReadyCondStatus corev1.ConditionStatus |
| 15 | +} |
| 16 | +tests := []struct { |
| 17 | +name string |
| 18 | +args args |
| 19 | +want bool |
| 20 | +}{ |
| 21 | +{ |
| 22 | +name: "suitable node changed from ready to notReady", |
| 23 | +args: args{ |
| 24 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 25 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 26 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 27 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 28 | +}, |
| 29 | +want: true, |
| 30 | +}, |
| 31 | +{ |
| 32 | +name: "suitable node changed from ready to unknown", |
| 33 | +args: args{ |
| 34 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 35 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 36 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 37 | +nodeNewReadyCondStatus: corev1.ConditionUnknown, |
| 38 | +}, |
| 39 | +want: true, |
| 40 | +}, |
| 41 | +{ |
| 42 | +name: "suitable node changed from notReady to ready", |
| 43 | +args: args{ |
| 44 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 45 | +nodeOldReadyCondStatus: corev1.ConditionFalse, |
| 46 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 47 | +nodeNewReadyCondStatus: corev1.ConditionTrue, |
| 48 | +}, |
| 49 | +want: true, |
| 50 | +}, |
| 51 | +{ |
| 52 | +name: "suitable node changed from notReady to unknown", |
| 53 | +args: args{ |
| 54 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 55 | +nodeOldReadyCondStatus: corev1.ConditionFalse, |
| 56 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 57 | +nodeNewReadyCondStatus: corev1.ConditionUnknown, |
| 58 | +}, |
| 59 | +want: true, |
| 60 | +}, |
| 61 | +{ |
| 62 | +name: "suitable node changed from unknown to ready", |
| 63 | +args: args{ |
| 64 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 65 | +nodeOldReadyCondStatus: corev1.ConditionUnknown, |
| 66 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 67 | +nodeNewReadyCondStatus: corev1.ConditionTrue, |
| 68 | +}, |
| 69 | +want: true, |
| 70 | +}, |
| 71 | +{ |
| 72 | +name: "suitable node changed from unknown to notReady", |
| 73 | +args: args{ |
| 74 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 75 | +nodeOldReadyCondStatus: corev1.ConditionUnknown, |
| 76 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 77 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 78 | +}, |
| 79 | +want: true, |
| 80 | +}, |
| 81 | +{ |
| 82 | +name: "suitable node remains ready", |
| 83 | +args: args{ |
| 84 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 85 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 86 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 87 | +nodeNewReadyCondStatus: corev1.ConditionTrue, |
| 88 | +}, |
| 89 | +want: false, |
| 90 | +}, |
| 91 | +{ |
| 92 | +name: "suitable node remains notReady", |
| 93 | +args: args{ |
| 94 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 95 | +nodeOldReadyCondStatus: corev1.ConditionFalse, |
| 96 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 97 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 98 | +}, |
| 99 | +want: false, |
| 100 | +}, |
| 101 | +{ |
| 102 | +name: "suitable node remains unknown", |
| 103 | +args: args{ |
| 104 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 105 | +nodeOldReadyCondStatus: corev1.ConditionUnknown, |
| 106 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 107 | +nodeNewReadyCondStatus: corev1.ConditionUnknown, |
| 108 | +}, |
| 109 | +want: false, |
| 110 | +}, |
| 111 | +{ |
| 112 | +name: "non-suitable node changed from ready to notReady", |
| 113 | +args: args{ |
| 114 | +nodeOldSuitableAsTrafficProxyForTGB: false, |
| 115 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 116 | +nodeNewSuitableAsTrafficProxyForTGB: false, |
| 117 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 118 | +}, |
| 119 | +want: false, |
| 120 | +}, |
| 121 | +{ |
| 122 | +name: "node became suitable while remains ready", |
| 123 | +args: args{ |
| 124 | +nodeOldSuitableAsTrafficProxyForTGB: false, |
| 125 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 126 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 127 | +nodeNewReadyCondStatus: corev1.ConditionTrue, |
| 128 | +}, |
| 129 | +want: true, |
| 130 | +}, |
| 131 | +{ |
| 132 | +name: "node became suitable while remains notReady", |
| 133 | +args: args{ |
| 134 | +nodeOldSuitableAsTrafficProxyForTGB: false, |
| 135 | +nodeOldReadyCondStatus: corev1.ConditionFalse, |
| 136 | +nodeNewSuitableAsTrafficProxyForTGB: true, |
| 137 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 138 | +}, |
| 139 | +want: false, |
| 140 | +}, |
| 141 | +{ |
| 142 | +name: "node became non-suitable while remains ready", |
| 143 | +args: args{ |
| 144 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 145 | +nodeOldReadyCondStatus: corev1.ConditionTrue, |
| 146 | +nodeNewSuitableAsTrafficProxyForTGB: false, |
| 147 | +nodeNewReadyCondStatus: corev1.ConditionTrue, |
| 148 | +}, |
| 149 | +want: true, |
| 150 | +}, |
| 151 | +{ |
| 152 | +name: "node became non-suitable while remains notReady", |
| 153 | +args: args{ |
| 154 | +nodeOldSuitableAsTrafficProxyForTGB: true, |
| 155 | +nodeOldReadyCondStatus: corev1.ConditionFalse, |
| 156 | +nodeNewSuitableAsTrafficProxyForTGB: false, |
| 157 | +nodeNewReadyCondStatus: corev1.ConditionFalse, |
| 158 | +}, |
| 159 | +want: false, |
| 160 | +}, |
| 161 | +} |
| 162 | +for _, tt := range tests { |
| 163 | +t.Run(tt.name, func(t *testing.T) { |
| 164 | +h := &enqueueRequestsForNodeEvent{} |
| 165 | +got := h.shouldEnqueueTGBDueToNodeEvent(tt.args.nodeOldSuitableAsTrafficProxyForTGB, tt.args.nodeOldReadyCondStatus, |
| 166 | +tt.args.nodeNewSuitableAsTrafficProxyForTGB, tt.args.nodeNewReadyCondStatus) |
| 167 | +assert.Equal(t, tt.want, got) |
| 168 | +}) |
| 169 | +} |
| 170 | +} |
0 commit comments