From 484510863bf7a53ba06faab725ec992de3551afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=9D=B0?= Date: Thu, 20 Jul 2023 16:33:18 +0800 Subject: [PATCH] e2e_windows: stop using deprecated framework.ExpectEqual --- test/e2e/windows/host_process.go | 17 +++-------------- test/e2e/windows/hyperv.go | 3 ++- test/e2e/windows/kubelet_stats.go | 5 +++-- test/e2e/windows/security_context.go | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/test/e2e/windows/host_process.go b/test/e2e/windows/host_process.go index 2b667847e07..156b5d821b3 100644 --- a/test/e2e/windows/host_process.go +++ b/test/e2e/windows/host_process.go @@ -724,15 +724,9 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi framework.Logf("Logs: %s\n", logs) - framework.ExpectEqual( - strings.Contains(logs, "calling /healthz"), - true, - "app logs should contain 'calling /healthz'") + gomega.Expect(logs).Should(gomega.ContainSubstring("calling /healthz"), "app logs should contain 'calling /healthz'") - framework.ExpectEqual( - strings.Contains(logs, "status=failed"), - false, - "app logs should not contain 'status=failed") + gomega.Expect(logs).ShouldNot(gomega.ContainSubstring("status=failed"), "app logs should not contain 'status=failed'") }) ginkgo.It("should run as localgroup accounts", func(ctx context.Context) { @@ -802,12 +796,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi logs, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, podName, "localgroup-container") framework.ExpectNoError(err, "error retrieving container logs") framework.Logf("Pod logs: %s", logs) - framework.ExpectEqual( - strings.Contains( - strings.ToLower(logs), - "nt authority"), - false, - "Container runs 'whoami' and logs should not contain 'nt authority'") + gomega.Expect(strings.ToLower(logs)).ShouldNot(gomega.ContainSubstring("nt authority"), "Container runs 'whoami' and logs should not contain 'nt authority'") }) }) diff --git a/test/e2e/windows/hyperv.go b/test/e2e/windows/hyperv.go index 9f370b75ff9..fe188d80b30 100644 --- a/test/e2e/windows/hyperv.go +++ b/test/e2e/windows/hyperv.go @@ -21,6 +21,7 @@ import ( "time" "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/test/e2e/framework" @@ -140,6 +141,6 @@ var _ = SIGDescribe("[Feature:WindowsHyperVContainers] HyperV containers", func( framework.Logf("Pod phase: %v\nlogs:\n%s", p.Status.Phase, logs) } - framework.ExpectEqual(p.Status.Phase, v1.PodSucceeded, "pod should have succeeded") + gomega.Expect(p.Status.Phase).To(gomega.Equal(v1.PodSucceeded), "pod should have succeeded") }) }) diff --git a/test/e2e/windows/kubelet_stats.go b/test/e2e/windows/kubelet_stats.go index b8ce353bf4b..7d5826e9eb0 100644 --- a/test/e2e/windows/kubelet_stats.go +++ b/test/e2e/windows/kubelet_stats.go @@ -34,6 +34,7 @@ import ( admissionapi "k8s.io/pod-security-admission/api" "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" ) var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() { @@ -97,7 +98,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() { } } } - framework.ExpectEqual(statsChecked, 10, "Should find stats for 10 pods in kubelet stats") + gomega.Expect(statsChecked).To(gomega.Equal(10), "Should find stats for 10 pods in kubelet stats") time.Sleep(5 * time.Second) } @@ -188,7 +189,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() { } } } - framework.ExpectEqual(statsChecked, 3, "Should find stats for 10 pods in kubelet stats") + gomega.Expect(statsChecked).To(gomega.Equal(3), "Should find stats for 3 pods in kubelet stats") time.Sleep(5 * time.Second) } diff --git a/test/e2e/windows/security_context.go b/test/e2e/windows/security_context.go index 14a3a54bd10..2278b80e2f8 100644 --- a/test/e2e/windows/security_context.go +++ b/test/e2e/windows/security_context.go @@ -170,7 +170,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() { framework.ExpectNotEqual(event, nil, "event should not be empty") framework.Logf("Got event: %v", event) expectedEventError := "container's runAsUserName (ContainerAdministrator) which will be regarded as root identity and will break non-root policy" - framework.ExpectEqual(true, strings.Contains(event.Message, expectedEventError), "Event error should indicate non-root policy caused container to not start") + gomega.Expect(event.Message).Should(gomega.ContainSubstring(expectedEventError), "Event error should indicate non-root policy caused container to not start") }) ginkgo.It("should not be able to create pods with containers running as CONTAINERADMINISTRATOR when runAsNonRoot is true", func(ctx context.Context) { @@ -188,7 +188,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() { framework.ExpectNotEqual(event, nil, "event should not be empty") framework.Logf("Got event: %v", event) expectedEventError := "container's runAsUserName (CONTAINERADMINISTRATOR) which will be regarded as root identity and will break non-root policy" - framework.ExpectEqual(true, strings.Contains(event.Message, expectedEventError), "Event error should indicate non-root policy caused container to not start") + gomega.Expect(event.Message).Should(gomega.ContainSubstring(expectedEventError), "Event error should indicate non-root policy caused container to not start") }) })