e2e: enhance tests that check for pod staying pending

Using WaitTimeoutForPodRunningInNamespace followed by ExpectError was not very
precise (any error passed the check, not just the expected timeout) and
hard to read. Now the test's expectation is spelled out explicitly: the pod
must stay in pending.
This commit is contained in:
Patrick Ohly
2022-10-24 17:26:07 +02:00
parent 6b5f77b163
commit 6af5bf0585
6 changed files with 41 additions and 29 deletions

View File

@@ -29,6 +29,7 @@ import (
admissionapi "k8s.io/pod-security-admission/api"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
// These tests exercise the Kubernetes expansion syntax $(VAR).
@@ -267,8 +268,8 @@ var _ = SIGDescribe("Variable Expansion", func() {
podClient := e2epod.NewPodClient(f)
pod = podClient.Create(ctx, pod)
err := e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout)
framework.ExpectError(err, "while waiting for pod to be running")
getPod := e2epod.Get(f.ClientSet, pod)
gomega.Consistently(ctx, getPod).WithTimeout(framework.PodStartShortTimeout).Should(e2epod.BeInPhase(v1.PodPending))
ginkgo.By("updating the pod")
podClient.Update(ctx, pod.ObjectMeta.Name, func(pod *v1.Pod) {
@@ -279,7 +280,7 @@ var _ = SIGDescribe("Variable Expansion", func() {
})
ginkgo.By("waiting for pod running")
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout)
err := e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout)
framework.ExpectNoError(err, "while waiting for pod to be running")
ginkgo.By("deleting the pod gracefully")