Skip to content

Commit 922b8ef

Browse files
authored
Merge pull request #11874 from sbueringer/pr-fix-mdr-unit-test
🐛 Fix MDR unit test
2 parents 1c864e0 + 4d9fac4 commit 922b8ef

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

internal/webhooks/test/machinedrainrules_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func Test_validate(t *testing.T) {
152152
"spec.pods[0].namespaceSelector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string(nil), MatchExpressions:[]v1.LabelSelectorRequirement{v1.LabelSelectorRequirement{Key:\"\", Operator:\"Invalid-Operator\", Values:[]string(nil)}}}: \"Invalid-Operator\" is not a valid label selector operator]",
153153
},
154154
{
155-
name: "Return error if selectors are not unique",
155+
name: "Return error if machine selectors are not unique",
156156
machineDrainRule: &clusterv1.MachineDrainRule{
157157
ObjectMeta: metav1.ObjectMeta{
158158
Name: "mdr",
@@ -188,6 +188,22 @@ func Test_validate(t *testing.T) {
188188
},
189189
},
190190
},
191+
},
192+
},
193+
wantErr: "MachineDrainRule.cluster.x-k8s.io \"mdr\" is invalid: " +
194+
"spec.machines: Invalid value: \"array\": entries in machines must be unique",
195+
},
196+
{
197+
name: "Return error if pod selectors are not unique",
198+
machineDrainRule: &clusterv1.MachineDrainRule{
199+
ObjectMeta: metav1.ObjectMeta{
200+
Name: "mdr",
201+
Namespace: metav1.NamespaceDefault,
202+
},
203+
Spec: clusterv1.MachineDrainRuleSpec{
204+
Drain: clusterv1.MachineDrainRuleDrainConfig{
205+
Behavior: clusterv1.MachineDrainRuleDrainBehaviorSkip,
206+
},
191207
Pods: []clusterv1.MachineDrainRulePodSelector{
192208
{
193209
Selector: &metav1.LabelSelector{
@@ -216,9 +232,8 @@ func Test_validate(t *testing.T) {
216232
},
217233
},
218234
},
219-
wantErr: "MachineDrainRule.cluster.x-k8s.io \"mdr\" is invalid: [" +
220-
"spec.machines: Invalid value: \"array\": entries in machines must be unique, " +
221-
"spec.pods: Invalid value: \"array\": entries in pods must be unique]",
235+
wantErr: "MachineDrainRule.cluster.x-k8s.io \"mdr\" is invalid: " +
236+
"spec.pods: Invalid value: \"array\": entries in pods must be unique",
222237
},
223238
}
224239

0 commit comments

Comments
 (0)