From a7748872621175b5b2f533db7e8a681f4db95645 Mon Sep 17 00:00:00 2001 From: jinye Date: Mon, 4 Sep 2023 20:01:40 +0800 Subject: [PATCH] cleanup:e2e:stop using deprecated framework.ExpectNotEqual --- test/e2e/common/node/secrets.go | 2 +- test/e2e/node/pods.go | 4 ++-- test/e2e_node/eviction_test.go | 11 ++++------ test/e2e_node/pod_conditions_test.go | 32 +++++++++++++++++++++------- test/e2e_node/util.go | 2 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/test/e2e/common/node/secrets.go b/test/e2e/common/node/secrets.go index 7bb2bfdc681..de7bc523aec 100644 --- a/test/e2e/common/node/secrets.go +++ b/test/e2e/common/node/secrets.go @@ -178,7 +178,7 @@ var _ = SIGDescribe("Secrets", func() { LabelSelector: "testsecret-constant=true", }) framework.ExpectNoError(err, "failed to list secrets") - framework.ExpectNotEqual(len(secretsList.Items), 0, "no secrets found") + gomega.Expect(secretsList.Items).ToNot(gomega.BeEmpty(), "no secrets found") foundCreatedSecret := false var secretCreatedName string diff --git a/test/e2e/node/pods.go b/test/e2e/node/pods.go index 3329a78a87e..555bf885760 100644 --- a/test/e2e/node/pods.go +++ b/test/e2e/node/pods.go @@ -138,8 +138,8 @@ var _ = SIGDescribe("Pods Extended", func() { }) framework.ExpectNoError(err, "kubelet never observed the termination notice") - framework.ExpectNotEqual(lastPod.DeletionTimestamp, nil) - framework.ExpectNotEqual(lastPod.Spec.TerminationGracePeriodSeconds, 0) + gomega.Expect(lastPod.DeletionTimestamp).ToNot(gomega.BeNil()) + gomega.Expect(lastPod.Spec.TerminationGracePeriodSeconds).ToNot(gomega.BeZero()) selector = labels.SelectorFromSet(labels.Set(map[string]string{"time": value})) options = metav1.ListOptions{LabelSelector: selector.String()} diff --git a/test/e2e_node/eviction_test.go b/test/e2e_node/eviction_test.go index 26ac88bdf38..0f38596f507 100644 --- a/test/e2e_node/eviction_test.go +++ b/test/e2e_node/eviction_test.go @@ -711,8 +711,7 @@ func verifyEvictionOrdering(ctx context.Context, f *framework.Framework, testSpe } } gomega.Expect(priorityPod).NotTo(gomega.BeNil()) - framework.ExpectNotEqual(priorityPod.Status.Phase, v1.PodSucceeded, - fmt.Sprintf("pod: %s succeeded unexpectedly", priorityPod.Name)) + gomega.Expect(priorityPod.Status.Phase).ToNot(gomega.Equal(v1.PodSucceeded), "pod: %s succeeded unexpectedly", priorityPod.Name) // Check eviction ordering. // Note: it is alright for a priority 1 and priority 2 pod (for example) to fail in the same round, @@ -726,9 +725,8 @@ func verifyEvictionOrdering(ctx context.Context, f *framework.Framework, testSpe } gomega.Expect(lowPriorityPod).NotTo(gomega.BeNil()) if priorityPodSpec.evictionPriority < lowPriorityPodSpec.evictionPriority && lowPriorityPod.Status.Phase == v1.PodRunning { - framework.ExpectNotEqual(priorityPod.Status.Phase, v1.PodFailed, - fmt.Sprintf("priority %d pod: %s failed before priority %d pod: %s", - priorityPodSpec.evictionPriority, priorityPodSpec.pod.Name, lowPriorityPodSpec.evictionPriority, lowPriorityPodSpec.pod.Name)) + gomega.Expect(priorityPod.Status.Phase).ToNot(gomega.Equal(v1.PodFailed), "priority %d pod: %s failed before priority %d pod: %s", + priorityPodSpec.evictionPriority, priorityPodSpec.pod.Name, lowPriorityPodSpec.evictionPriority, lowPriorityPodSpec.pod.Name) } } @@ -739,8 +737,7 @@ func verifyEvictionOrdering(ctx context.Context, f *framework.Framework, testSpe // EvictionPriority 0 pods should not fail if priorityPodSpec.evictionPriority == 0 { - framework.ExpectNotEqual(priorityPod.Status.Phase, v1.PodFailed, - fmt.Sprintf("priority 0 pod: %s failed", priorityPod.Name)) + gomega.Expect(priorityPod.Status.Phase).ToNot(gomega.Equal(v1.PodFailed), "priority 0 pod: %s failed", priorityPod.Name) } // If a pod that is not evictionPriority 0 has not been evicted, we are not done diff --git a/test/e2e_node/pod_conditions_test.go b/test/e2e_node/pod_conditions_test.go index 1c8cf61bb59..2406fbddcc3 100644 --- a/test/e2e_node/pod_conditions_test.go +++ b/test/e2e_node/pod_conditions_test.go @@ -125,7 +125,9 @@ func runPodFailingConditionsTest(f *framework.Framework, hasInitContainers, chec // Verify PodInitialized is set if init containers are not present (since without init containers, it gets set very early) initializedTime, err := getTransitionTimeForPodConditionWithStatus(p, v1.PodInitialized, true) framework.ExpectNoError(err) - framework.ExpectNotEqual(initializedTime.Before(scheduledTime), true, fmt.Sprintf("pod without init containers is initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime)) + if initializedTime.Before(scheduledTime) { + framework.Failf("pod without init containers is initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime) + } } // Verify ContainersReady is not set (since sandboxcreation is blocked) @@ -165,28 +167,42 @@ func runPodReadyConditionsTest(f *framework.Framework, hasInitContainers, checkP if hasInitContainers { // With init containers, verify the sequence of conditions is: Scheduled => PodReadyToStartContainers => Initialized - framework.ExpectNotEqual(readyToStartContainersTime.Before(scheduledTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime)) - framework.ExpectNotEqual(initializedTime.Before(readyToStartContainersTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime)) + if readyToStartContainersTime.Before(scheduledTime) { + framework.Failf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime) + } + if initializedTime.Before(readyToStartContainersTime) { + framework.Failf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime) + } } else { // Without init containers, verify the sequence of conditions is: Scheduled => Initialized => PodReadyToStartContainers condBeforeContainersReadyTransitionTime = readyToStartContainersTime errSubstrIfContainersReadyTooEarly = "ready to start" - framework.ExpectNotEqual(initializedTime.Before(scheduledTime), true, fmt.Sprintf("pod without init containers initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime)) - framework.ExpectNotEqual(readyToStartContainersTime.Before(initializedTime), true, fmt.Sprintf("pod without init containers has ready to start at: %v which is before pod is initialized at: %v", readyToStartContainersTime, initializedTime)) + if initializedTime.Before(scheduledTime) { + framework.Failf("pod without init containers initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime) + } + if readyToStartContainersTime.Before(initializedTime) { + framework.Failf("pod without init containers has ready to start at: %v which is before pod is initialized at: %v", readyToStartContainersTime, initializedTime) + } } } else { // In the absence of PodHasReadyToStartContainers feature disabled, verify the sequence is: Scheduled => Initialized - framework.ExpectNotEqual(initializedTime.Before(scheduledTime), true, fmt.Sprintf("pod initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime)) + if initializedTime.Before(scheduledTime) { + framework.Failf("pod initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime) + } } // Verify the next condition to get set is ContainersReady containersReadyTime, err := getTransitionTimeForPodConditionWithStatus(p, v1.ContainersReady, true) framework.ExpectNoError(err) - framework.ExpectNotEqual(containersReadyTime.Before(condBeforeContainersReadyTransitionTime), true, fmt.Sprintf("containers ready at: %v which is before pod %s: %v", containersReadyTime, errSubstrIfContainersReadyTooEarly, initializedTime)) + if containersReadyTime.Before(condBeforeContainersReadyTransitionTime) { + framework.Failf("containers ready at: %v which is before pod %s: %v", containersReadyTime, errSubstrIfContainersReadyTooEarly, initializedTime) + } // Verify ContainersReady => PodReady podReadyTime, err := getTransitionTimeForPodConditionWithStatus(p, v1.PodReady, true) framework.ExpectNoError(err) - framework.ExpectNotEqual(podReadyTime.Before(containersReadyTime), true, fmt.Sprintf("pod ready at: %v which is before pod containers ready at: %v", podReadyTime, containersReadyTime)) + if podReadyTime.Before(containersReadyTime) { + framework.Failf("pod ready at: %v which is before pod containers ready at: %v", podReadyTime, containersReadyTime) + } } } diff --git a/test/e2e_node/util.go b/test/e2e_node/util.go index 8c2a15bbb04..1579d4de9c2 100644 --- a/test/e2e_node/util.go +++ b/test/e2e_node/util.go @@ -359,7 +359,7 @@ func findKubeletServiceName(running bool) string { framework.ExpectNoError(err) regex := regexp.MustCompile("(kubelet-\\w+)") matches := regex.FindStringSubmatch(string(stdout)) - framework.ExpectNotEqual(len(matches), 0, "Found more than one kubelet service running: %q", stdout) + gomega.Expect(matches).ToNot(gomega.BeEmpty(), "Found more than one kubelet service running: %q", stdout) kubeletServiceName := matches[0] framework.Logf("Get running kubelet with systemctl: %v, %v", string(stdout), kubeletServiceName) return kubeletServiceName