Skip to content

Commit d770dd6

Browse files
authored
Merge pull request kubernetes#121888 from SD-13/e2e-gomega-be-true-or-false
Enhance boolean assertions when fail
2 parents b8dcc2c + 223aedc commit d770dd6

35 files changed

+135
-161
lines changed

hack/verify-golangci-lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Usage: $0 [-r <revision>|-a] [-s] [-c none|<config>] [-- <golangci-lint run flag
2626
-a: automatically select the common base of origin/master and HEAD
2727
as revision
2828
-s: select a strict configuration for new code
29-
-n: in addition to strict checking, also enable hints (aka nits) that may are may not
29+
-n: in addition to strict checking, also enable hints (aka nits) that may or may not
3030
be useful
3131
-g <github action file>: also write results with --out-format=github-actions
3232
to a separate file

test/e2e/apimachinery/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ var _ = SIGDescribe("Discovery", func() {
308308
break
309309
}
310310
}
311-
gomega.Expect(foundResource).To(gomega.BeTrue(), "Resource %q was not found inside of resourceList\n%#v", t.validResource, resourceList.APIResources)
311+
gomega.Expect(foundResource).To(gomega.BeTrueBecause("Resource %q was not found inside of resourceList\n%#v", t.validResource, resourceList.APIResources))
312312
}
313313
})
314314
})

test/e2e/apimachinery/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var _ = SIGDescribe("client-go should negotiate", func() {
7272
defer w.Stop()
7373

7474
evt, ok := <-w.ResultChan()
75-
o.Expect(ok).To(o.BeTrue())
75+
o.Expect(ok).To(o.BeTrueBecause("unexpected watch event: %v, %#v", evt.Type, evt.Object))
7676
switch evt.Type {
7777
case watch.Added, watch.Modified:
7878
// this is allowed

test/e2e/apimachinery/webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
825825
_, err := createValidatingWebhookConfiguration(ctx, f, validatingWebhookConfiguration)
826826
gomega.Expect(err).To(gomega.HaveOccurred(), "create validatingwebhookconfiguration should have been denied by the api-server")
827827
expectedErrMsg := "compilation failed"
828-
gomega.Expect(strings.Contains(err.Error(), expectedErrMsg)).To(gomega.BeTrue())
828+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedErrMsg)))
829829
})
830830

831831
/*
@@ -849,7 +849,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
849849
_, err := createMutatingWebhookConfiguration(ctx, f, mutatingWebhookConfiguration)
850850
gomega.Expect(err).To(gomega.HaveOccurred(), "create mutatingwebhookconfiguration should have been denied by the api-server")
851851
expectedErrMsg := "compilation failed"
852-
gomega.Expect(strings.Contains(err.Error(), expectedErrMsg)).To(gomega.BeTrue())
852+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedErrMsg)))
853853
})
854854

855855
/*
@@ -908,7 +908,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
908908
"mutation-start": "yes",
909909
"mutation-stage-1": "yes",
910910
}
911-
gomega.Expect(reflect.DeepEqual(expectedConfigMapData, mutatedCM.Data)).To(gomega.BeTrue())
911+
gomega.Expect(mutatedCM.Data).Should(gomega.Equal(expectedConfigMapData))
912912

913913
ginkgo.By("create the configmap with 'skip-me' name")
914914

@@ -918,7 +918,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
918918
expectedConfigMapData = map[string]string{
919919
"mutation-start": "yes",
920920
}
921-
gomega.Expect(reflect.DeepEqual(expectedConfigMapData, skippedCM.Data)).To(gomega.BeTrue())
921+
gomega.Expect(skippedCM.Data).Should(gomega.Equal(expectedConfigMapData))
922922
})
923923
})
924924

test/e2e/apps/disruption.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ var _ = SIGDescribe("DisruptionController", func() {
209209
return false, err
210210
}
211211
return isPDBErroring(pdb), nil
212-
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod shouldn't error for "+
213-
"unmanaged pod")
212+
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod shouldn't error for " +
213+
"unmanaged pod"))
214214
})
215215

216216
evictionCases := []struct {

test/e2e/common/node/container_probe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var _ = SIGDescribe("Probing container", func() {
113113
return false, err
114114
}
115115
return podutil.IsPodReady(p), nil
116-
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod should not be ready")
116+
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod should not be ready"))
117117

118118
p, err := podClient.Get(ctx, p.Name, metav1.GetOptions{})
119119
framework.ExpectNoError(err)
@@ -726,7 +726,7 @@ done
726726
}
727727
}
728728
return false, nil
729-
}, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrue(), "should not see liveness probes")
729+
}, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrueBecause("should not see liveness probes"))
730730
})
731731
})
732732

@@ -792,7 +792,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, feature.SidecarContainers, "P
792792
return false, err
793793
}
794794
return podutil.IsPodReady(p), nil
795-
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod should not be ready")
795+
}, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod should not be ready"))
796796

797797
p, err := podClient.Get(ctx, p.Name, metav1.GetOptions{})
798798
framework.ExpectNoError(err)
@@ -1484,7 +1484,7 @@ done
14841484
}
14851485
}
14861486
return false, nil
1487-
}, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrue(), "should not see liveness probes")
1487+
}, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrueBecause("should not see liveness probes"))
14881488
})
14891489
})
14901490

test/e2e/framework/log_test.go

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ var _ = ginkgo.Describe("log", func() {
5050
})
5151
ginkgo.AfterEach(func() {
5252
framework.Logf("after")
53-
gomega.Expect(true).To(gomega.BeFalse(), "true is never false either")
53+
gomega.Expect(true).To(gomega.BeFalseBecause("artificial assertion failure"))
5454
})
5555
ginkgo.It("fails", func() {
5656
func() {
5757
framework.Failf("I'm failing.")
5858
}()
5959
})
6060
ginkgo.It("asserts", func() {
61-
gomega.Expect(false).To(gomega.BeTrue(), "false is never true")
61+
gomega.Expect(false).To(gomega.BeTrueBecause("artificial assertion failure"))
6262
})
6363
ginkgo.It("error", func() {
6464
err := errors.New("an error with a long, useless description")
@@ -106,10 +106,7 @@ In [It] at: log_test.go:57 <time>
106106
< Exit [It] fails - log_test.go:55 <time>
107107
> Enter [AfterEach] log - log_test.go:51 <time>
108108
<klog> log_test.go:52] after
109-
[FAILED] true is never false either
110-
Expected
111-
<bool>: true
112-
to be false
109+
[FAILED] artificial assertion failure
113110
In [AfterEach] at: log_test.go:53 <time>
114111
< Exit [AfterEach] log - log_test.go:51 <time>
115112
`,
@@ -119,10 +116,7 @@ In [AfterEach] at: log_test.go:53 <time>
119116
Status: "failed",
120117
Failure: &reporters.JUnitFailure{
121118
Type: "failed",
122-
Description: `[FAILED] false is never true
123-
Expected
124-
<bool>: false
125-
to be true
119+
Description: `[FAILED] artificial assertion failure
126120
In [It] at: log_test.go:61 <time>
127121
128122
There were additional failures detected after the initial failure. These are visible in the timeline
@@ -132,18 +126,12 @@ There were additional failures detected after the initial failure. These are vis
132126
<klog> log_test.go:49] before
133127
< Exit [BeforeEach] log - log_test.go:48 <time>
134128
> Enter [It] asserts - log_test.go:60 <time>
135-
[FAILED] false is never true
136-
Expected
137-
<bool>: false
138-
to be true
129+
[FAILED] artificial assertion failure
139130
In [It] at: log_test.go:61 <time>
140131
< Exit [It] asserts - log_test.go:60 <time>
141132
> Enter [AfterEach] log - log_test.go:51 <time>
142133
<klog> log_test.go:52] after
143-
[FAILED] true is never false either
144-
Expected
145-
<bool>: true
146-
to be false
134+
[FAILED] artificial assertion failure
147135
In [AfterEach] at: log_test.go:53 <time>
148136
< Exit [AfterEach] log - log_test.go:51 <time>
149137
`,
@@ -174,10 +162,7 @@ In [It] at: log_test.go:65 <time>
174162
< Exit [It] error - log_test.go:63 <time>
175163
> Enter [AfterEach] log - log_test.go:51 <time>
176164
<klog> log_test.go:52] after
177-
[FAILED] true is never false either
178-
Expected
179-
<bool>: true
180-
to be false
165+
[FAILED] artificial assertion failure
181166
In [AfterEach] at: log_test.go:53 <time>
182167
< Exit [AfterEach] log - log_test.go:51 <time>
183168
`,
@@ -210,10 +195,7 @@ In [It] at: log_test.go:68 <time>
210195
< Exit [It] equal - log_test.go:67 <time>
211196
> Enter [AfterEach] log - log_test.go:51 <time>
212197
<klog> log_test.go:52] after
213-
[FAILED] true is never false either
214-
Expected
215-
<bool>: true
216-
to be false
198+
[FAILED] artificial assertion failure
217199
In [AfterEach] at: log_test.go:53 <time>
218200
< Exit [AfterEach] log - log_test.go:51 <time>
219201
`,
@@ -238,10 +220,7 @@ In [It] at: log_test.go:44 <time>
238220
< Exit [It] fails with helper - log_test.go:70 <time>
239221
> Enter [AfterEach] log - log_test.go:51 <time>
240222
<klog> log_test.go:52] after
241-
[FAILED] true is never false either
242-
Expected
243-
<bool>: true
244-
to be false
223+
[FAILED] artificial assertion failure
245224
In [AfterEach] at: log_test.go:53 <time>
246225
< Exit [AfterEach] log - log_test.go:51 <time>
247226
`,
@@ -251,10 +230,7 @@ In [AfterEach] at: log_test.go:53 <time>
251230
Status: "failed",
252231
Failure: &reporters.JUnitFailure{
253232
Type: "failed",
254-
Description: `[FAILED] true is never false either
255-
Expected
256-
<bool>: true
257-
to be false
233+
Description: `[FAILED] artificial assertion failure
258234
In [AfterEach] at: log_test.go:53 <time>
259235
`,
260236
},
@@ -267,10 +243,7 @@ In [AfterEach] at: log_test.go:53 <time>
267243
< Exit [It] redirects klog - log_test.go:73 <time>
268244
> Enter [AfterEach] log - log_test.go:51 <time>
269245
<klog> log_test.go:52] after
270-
[FAILED] true is never false either
271-
Expected
272-
<bool>: true
273-
to be false
246+
[FAILED] artificial assertion failure
274247
In [AfterEach] at: log_test.go:53 <time>
275248
< Exit [AfterEach] log - log_test.go:51 <time>
276249
`,

test/e2e/framework/pod/pod_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (c *PodClient) mungeSpec(pod *v1.Pod) {
266266
}
267267
// If the image policy is not PullAlways, the image must be in the pre-pull list and
268268
// pre-pulled.
269-
gomega.Expect(ImagePrePullList.Has(c.Image)).To(gomega.BeTrue(), "Image %q is not in the pre-pull list, consider adding it to PrePulledImages in test/e2e/common/util.go or NodePrePullImageList in test/e2e_node/image_list.go", c.Image)
269+
gomega.Expect(ImagePrePullList.Has(c.Image)).To(gomega.BeTrueBecause("Image %q is not in the pre-pull list, consider adding it to PrePulledImages in test/e2e/common/util.go or NodePrePullImageList in test/e2e_node/image_list.go", c.Image))
270270
// Do not pull images during the tests because the images in pre-pull list should have
271271
// been prepulled.
272272
c.ImagePullPolicy = v1.PullNever

test/e2e/storage/testsuites/volume_expand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver storageframework.TestDriver,
178178

179179
gomega.Expect(l.resource.Sc.AllowVolumeExpansion).NotTo(gomega.BeNil())
180180
allowVolumeExpansion := *l.resource.Sc.AllowVolumeExpansion
181-
gomega.Expect(allowVolumeExpansion).To(gomega.BeFalse())
181+
gomega.Expect(allowVolumeExpansion).To(gomega.BeFalseBecause("expected AllowVolumeExpansion value to be false"))
182182
ginkgo.By("Expanding non-expandable pvc")
183183
currentPvcSize := l.resource.Pvc.Spec.Resources.Requests[v1.ResourceStorage]
184184
newSize := currentPvcSize.DeepCopy()

test/e2e/windows/density.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func runDensityBatchTest(ctx context.Context, f *framework.Framework, testArg de
116116

117117
gomega.Eventually(ctx, func() bool {
118118
return len(watchTimes) == testArg.podsNr
119-
}, 10*time.Minute, 10*time.Second).Should(gomega.BeTrue())
119+
}, 10*time.Minute, 10*time.Second).Should(gomega.BeTrueBecause("All pods should be observed by the watch."))
120120

121121
if len(watchTimes) < testArg.podsNr {
122122
framework.Failf("Timeout reached waiting for all Pods to be observed by the watch.")

0 commit comments

Comments
 (0)