Skip to content

Commit f407dfe

Browse files
authored
Merge pull request #13170 from sbueringer/pr-fix-envtest-tests
🐛 Fix webhook envtest tests for Kubernetes < v1.35
2 parents f1c21c4 + 807bb57 commit f407dfe

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

internal/webhooks/test/machinedrainrules_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ func Test_validate(t *testing.T) {
190190
},
191191
},
192192
},
193-
wantErr: "MachineDrainRule.cluster.x-k8s.io \"mdr\" is invalid: " +
194-
"spec.machines: Invalid value: entries in machines must be unique",
193+
wantErr: "entries in machines must be unique",
195194
},
196195
{
197196
name: "Return error if pod selectors are not unique",
@@ -232,8 +231,7 @@ func Test_validate(t *testing.T) {
232231
},
233232
},
234233
},
235-
wantErr: "MachineDrainRule.cluster.x-k8s.io \"mdr\" is invalid: " +
236-
"spec.pods: Invalid value: entries in pods must be unique",
234+
wantErr: "entries in pods must be unique",
237235
},
238236
}
239237

@@ -245,7 +243,7 @@ func Test_validate(t *testing.T) {
245243

246244
if tt.wantErr != "" {
247245
g.Expect(err).To(HaveOccurred())
248-
g.Expect(err.Error()).To(BeComparableTo(tt.wantErr))
246+
g.Expect(err.Error()).To(ContainSubstring(tt.wantErr))
249247
} else {
250248
g.Expect(err).ToNot(HaveOccurred())
251249
g.Expect(env.CleanupAndWait(ctx, tt.machineDrainRule)).To(Succeed())

internal/webhooks/test/machinehealthcheck_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
8383
},
8484
},
8585
},
86-
wantErr: "MachineHealthCheck.cluster.x-k8s.io \"mhc\" is invalid: " +
87-
"spec.checks.unhealthyMachineConditions[0].type: Invalid value: \"Ready\": type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
86+
wantErr: "type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
8887
},
8988
{
9089
name: "Return error if UnhealthyMachineCondition type is 'Available'",
@@ -111,8 +110,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
111110
},
112111
},
113112
},
114-
wantErr: "MachineHealthCheck.cluster.x-k8s.io \"mhc\" is invalid: " +
115-
"spec.checks.unhealthyMachineConditions[0].type: Invalid value: \"Available\": type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
113+
wantErr: "type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
116114
},
117115
{
118116
name: "Return error if UnhealthyMachineCondition type is 'HealthCheckSucceeded'",
@@ -139,8 +137,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
139137
},
140138
},
141139
},
142-
wantErr: "MachineHealthCheck.cluster.x-k8s.io \"mhc\" is invalid: " +
143-
"spec.checks.unhealthyMachineConditions[0].type: Invalid value: \"HealthCheckSucceeded\": type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
140+
wantErr: "type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
144141
},
145142
{
146143
name: "Return error if UnhealthyMachineCondition type is 'OwnerRemediated'",
@@ -167,8 +164,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
167164
},
168165
},
169166
},
170-
wantErr: "MachineHealthCheck.cluster.x-k8s.io \"mhc\" is invalid: " +
171-
"spec.checks.unhealthyMachineConditions[0].type: Invalid value: \"OwnerRemediated\": type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
167+
wantErr: "type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
172168
},
173169
{
174170
name: "Return error if UnhealthyMachineCondition type is 'ExternallyRemediated'",
@@ -195,8 +191,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
195191
},
196192
},
197193
},
198-
wantErr: "MachineHealthCheck.cluster.x-k8s.io \"mhc\" is invalid: " +
199-
"spec.checks.unhealthyMachineConditions[0].type: Invalid value: \"ExternallyRemediated\": type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
194+
wantErr: "type must not be one of: Ready, Available, HealthCheckSucceeded, OwnerRemediated, ExternallyRemediated",
200195
},
201196
{
202197
name: "Return no error if UnhealthyMachineCondition type is allowed custom type",
@@ -234,7 +229,7 @@ func Test_validateMachineHealthCheck(t *testing.T) {
234229

235230
if tt.wantErr != "" {
236231
g.Expect(err).To(HaveOccurred())
237-
g.Expect(err.Error()).To(BeComparableTo(tt.wantErr))
232+
g.Expect(err.Error()).To(ContainSubstring(tt.wantErr))
238233
} else {
239234
g.Expect(err).ToNot(HaveOccurred())
240235
g.Expect(env.CleanupAndWait(ctx, tt.machineHealthCheck)).To(Succeed())

0 commit comments

Comments
 (0)