From 223aedcf6b5dc693d29b839669b7f897305fb3d2 Mon Sep 17 00:00:00 2001 From: Sujay <89520981+SD-13@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:58:15 +0000 Subject: [PATCH] enhance boolean assertions --- hack/verify-golangci-lint.sh | 2 +- test/e2e/apimachinery/discovery.go | 2 +- test/e2e/apimachinery/protocol.go | 2 +- test/e2e/apimachinery/webhook.go | 8 ++-- test/e2e/apps/disruption.go | 4 +- test/e2e/common/node/container_probe.go | 8 ++-- test/e2e/framework/log_test.go | 49 +++++--------------- test/e2e/framework/pod/pod_client.go | 2 +- test/e2e/storage/testsuites/volume_expand.go | 2 +- test/e2e/windows/density.go | 2 +- test/e2e/windows/gmsa_full.go | 27 +++++------ test/e2e/windows/gmsa_kubelet.go | 9 ++-- test/e2e/windows/memory_limits.go | 2 +- test/e2e/windows/security_context.go | 2 +- test/e2e_kubeadm/kubeadm_certs_test.go | 2 +- test/e2e_kubeadm/util.go | 2 +- test/e2e_node/container_lifecycle_test.go | 8 ++-- test/e2e_node/cpu_manager_test.go | 6 +-- test/e2e_node/density_test.go | 2 +- test/e2e_node/device_plugin_test.go | 44 +++++++++--------- test/e2e_node/hugepages_test.go | 15 +++--- test/e2e_node/kubelet_config_dir_test.go | 4 +- test/e2e_node/lock_contention_linux_test.go | 4 +- test/e2e_node/memory_manager_test.go | 8 ++-- test/e2e_node/mirror_pod_test.go | 4 +- test/e2e_node/node_container_manager_test.go | 8 ++-- test/e2e_node/node_perf_test.go | 6 +-- test/e2e_node/pod_conditions_test.go | 16 +++---- test/e2e_node/podresources_test.go | 4 +- test/e2e_node/restart_test.go | 18 +++---- test/e2e_node/swap_test.go | 2 +- test/e2e_node/terminate_pods_test.go | 4 +- test/e2e_node/topology_manager_test.go | 4 +- test/e2e_node/unknown_pods_test.go | 8 ++-- test/e2e_node/util.go | 6 +-- 35 files changed, 135 insertions(+), 161 deletions(-) diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index d05276300d9..8bf4843cd61 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -26,7 +26,7 @@ Usage: $0 [-r |-a] [-s] [-c none|] [-- : also write results with --out-format=github-actions to a separate file diff --git a/test/e2e/apimachinery/discovery.go b/test/e2e/apimachinery/discovery.go index c20d470cc5e..f98ce820bf3 100644 --- a/test/e2e/apimachinery/discovery.go +++ b/test/e2e/apimachinery/discovery.go @@ -308,7 +308,7 @@ var _ = SIGDescribe("Discovery", func() { break } } - gomega.Expect(foundResource).To(gomega.BeTrue(), "Resource %q was not found inside of resourceList\n%#v", t.validResource, resourceList.APIResources) + gomega.Expect(foundResource).To(gomega.BeTrueBecause("Resource %q was not found inside of resourceList\n%#v", t.validResource, resourceList.APIResources)) } }) }) diff --git a/test/e2e/apimachinery/protocol.go b/test/e2e/apimachinery/protocol.go index 7a1bdfe124d..b40f52275a0 100644 --- a/test/e2e/apimachinery/protocol.go +++ b/test/e2e/apimachinery/protocol.go @@ -72,7 +72,7 @@ var _ = SIGDescribe("client-go should negotiate", func() { defer w.Stop() evt, ok := <-w.ResultChan() - o.Expect(ok).To(o.BeTrue()) + o.Expect(ok).To(o.BeTrueBecause("unexpected watch event: %v, %#v", evt.Type, evt.Object)) switch evt.Type { case watch.Added, watch.Modified: // this is allowed diff --git a/test/e2e/apimachinery/webhook.go b/test/e2e/apimachinery/webhook.go index c78ce831765..e8a6494b39f 100644 --- a/test/e2e/apimachinery/webhook.go +++ b/test/e2e/apimachinery/webhook.go @@ -828,7 +828,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() { _, err := createValidatingWebhookConfiguration(ctx, f, validatingWebhookConfiguration) gomega.Expect(err).To(gomega.HaveOccurred(), "create validatingwebhookconfiguration should have been denied by the api-server") expectedErrMsg := "compilation failed" - gomega.Expect(strings.Contains(err.Error(), expectedErrMsg)).To(gomega.BeTrue()) + gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedErrMsg))) }) /* @@ -852,7 +852,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() { _, err := createMutatingWebhookConfiguration(ctx, f, mutatingWebhookConfiguration) gomega.Expect(err).To(gomega.HaveOccurred(), "create mutatingwebhookconfiguration should have been denied by the api-server") expectedErrMsg := "compilation failed" - gomega.Expect(strings.Contains(err.Error(), expectedErrMsg)).To(gomega.BeTrue()) + gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedErrMsg))) }) /* @@ -911,7 +911,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() { "mutation-start": "yes", "mutation-stage-1": "yes", } - gomega.Expect(reflect.DeepEqual(expectedConfigMapData, mutatedCM.Data)).To(gomega.BeTrue()) + gomega.Expect(mutatedCM.Data).Should(gomega.Equal(expectedConfigMapData)) ginkgo.By("create the configmap with 'skip-me' name") @@ -921,7 +921,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() { expectedConfigMapData = map[string]string{ "mutation-start": "yes", } - gomega.Expect(reflect.DeepEqual(expectedConfigMapData, skippedCM.Data)).To(gomega.BeTrue()) + gomega.Expect(skippedCM.Data).Should(gomega.Equal(expectedConfigMapData)) }) }) diff --git a/test/e2e/apps/disruption.go b/test/e2e/apps/disruption.go index 690f4d85adc..4eeecead1e6 100644 --- a/test/e2e/apps/disruption.go +++ b/test/e2e/apps/disruption.go @@ -206,8 +206,8 @@ var _ = SIGDescribe("DisruptionController", func() { return false, err } return isPDBErroring(pdb), nil - }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod shouldn't error for "+ - "unmanaged pod") + }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod shouldn't error for " + + "unmanaged pod")) }) evictionCases := []struct { diff --git a/test/e2e/common/node/container_probe.go b/test/e2e/common/node/container_probe.go index 534fc26bf97..dda079fef57 100644 --- a/test/e2e/common/node/container_probe.go +++ b/test/e2e/common/node/container_probe.go @@ -113,7 +113,7 @@ var _ = SIGDescribe("Probing container", func() { return false, err } return podutil.IsPodReady(p), nil - }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod should not be ready") + }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod should not be ready")) p, err := podClient.Get(ctx, p.Name, metav1.GetOptions{}) framework.ExpectNoError(err) @@ -726,7 +726,7 @@ done } } return false, nil - }, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrue(), "should not see liveness probes") + }, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrueBecause("should not see liveness probes")) }) }) @@ -792,7 +792,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, feature.SidecarContainers, "P return false, err } return podutil.IsPodReady(p), nil - }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrue(), "pod should not be ready") + }, 1*time.Minute, 1*time.Second).ShouldNot(gomega.BeTrueBecause("pod should not be ready")) p, err := podClient.Get(ctx, p.Name, metav1.GetOptions{}) framework.ExpectNoError(err) @@ -1484,7 +1484,7 @@ done } } return false, nil - }, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrue(), "should not see liveness probes") + }, 1*time.Minute, framework.Poll).ShouldNot(gomega.BeTrueBecause("should not see liveness probes")) }) }) diff --git a/test/e2e/framework/log_test.go b/test/e2e/framework/log_test.go index 207f9cb8ec9..18543f72fdb 100644 --- a/test/e2e/framework/log_test.go +++ b/test/e2e/framework/log_test.go @@ -50,7 +50,7 @@ var _ = ginkgo.Describe("log", func() { }) ginkgo.AfterEach(func() { framework.Logf("after") - gomega.Expect(true).To(gomega.BeFalse(), "true is never false either") + gomega.Expect(true).To(gomega.BeFalseBecause("artificial assertion failure")) }) ginkgo.It("fails", func() { func() { @@ -58,7 +58,7 @@ var _ = ginkgo.Describe("log", func() { }() }) ginkgo.It("asserts", func() { - gomega.Expect(false).To(gomega.BeTrue(), "false is never true") + gomega.Expect(false).To(gomega.BeTrueBecause("artificial assertion failure")) }) ginkgo.It("error", func() { err := errors.New("an error with a long, useless description") @@ -106,10 +106,7 @@ In [It] at: log_test.go:57