From d5a56739cee6992e31c67229d37e5e92437203af Mon Sep 17 00:00:00 2001 From: carlory Date: Fri, 9 May 2025 16:48:48 +0800 Subject: [PATCH] use framework.ExpectNoError instead Co-authored-by: Patrick Ohly Signed-off-by: carlory --- test/e2e/framework/pod/delete.go | 2 +- test/e2e/framework/pod/resource.go | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/test/e2e/framework/pod/delete.go b/test/e2e/framework/pod/delete.go index 360862d3438..57bb67a9faa 100644 --- a/test/e2e/framework/pod/delete.go +++ b/test/e2e/framework/pod/delete.go @@ -44,7 +44,7 @@ func DeletePodOrFail(ctx context.Context, c clientset.Interface, ns, name string return } - expectNoError(err, "failed to delete pod %s in namespace %s", name, ns) + framework.ExpectNoErrorWithOffset(1, err, "failed to delete pod %s in namespace %s", name, ns) } // DeletePodWithWait deletes the passed-in pod and waits for the pod to be terminated. Resilient to the pod diff --git a/test/e2e/framework/pod/resource.go b/test/e2e/framework/pod/resource.go index 6dc039587e5..ca2b63a13ba 100644 --- a/test/e2e/framework/pod/resource.go +++ b/test/e2e/framework/pod/resource.go @@ -26,7 +26,6 @@ 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/apimachinery/pkg/labels" @@ -43,22 +42,6 @@ import ( // have their logs fetched. const LabelLogOnPodFailure = "log-on-pod-failure" -// TODO: Move to its own subpkg. -// expectNoError checks if "err" is set, and if so, fails assertion while logging the error. -func expectNoError(err error, explain ...interface{}) { - expectNoErrorWithOffset(1, err, explain...) -} - -// TODO: Move to its own subpkg. -// expectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller -// (for example, for call chain f -> g -> expectNoErrorWithOffset(1, ...) error would be logged for "f"). -func expectNoErrorWithOffset(offset int, err error, explain ...interface{}) { - if err != nil { - framework.Logf("Unexpected error occurred: %v", err) - } - gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...) -} - // PodsCreatedByLabel returns a created pod list matched by the given label. func PodsCreatedByLabel(ctx context.Context, c clientset.Interface, ns, name string, replicas int32, label labels.Selector) (*v1.PodList, error) { timeout := 2 * time.Minute @@ -364,9 +347,9 @@ func CreateExecPodOrFail(ctx context.Context, client clientset.Interface, ns, ge tweak(pod) } execPod, err := client.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}) - expectNoError(err, "failed to create new exec pod in namespace: %s", ns) + framework.ExpectNoErrorWithOffset(1, err, "failed to create new exec pod in namespace: %s", ns) err = WaitForPodNameRunningInNamespace(ctx, client, execPod.Name, execPod.Namespace) - expectNoError(err, "failed to create new exec pod in namespace: %s", ns) + framework.ExpectNoErrorWithOffset(1, err, "failed to create new exec pod in namespace: %s", ns) return execPod }