From 7401f2fe9b5fd474938436712a6af63a362ce429 Mon Sep 17 00:00:00 2001 From: Jianfei Bai Date: Sun, 27 Oct 2019 11:54:32 +0800 Subject: [PATCH] move funcs of expect.go to e2e/common --- test/e2e/common/pods.go | 19 ++++++++++++++++++- test/e2e/framework/expect.go | 18 ------------------ test/e2e/framework/pod/resource.go | 1 - 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/test/e2e/common/pods.go b/test/e2e/common/pods.go index 59091b49b914..a9a399a488d0 100644 --- a/test/e2e/common/pods.go +++ b/test/e2e/common/pods.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "io" + "runtime/debug" "strconv" "strings" "time" @@ -158,6 +159,22 @@ func getRestartDelay(podClient *framework.PodClient, podName string, containerNa return 0, fmt.Errorf("timeout getting pod restart delay") } +// expectNoErrorWithRetries checks if an error occurs with the given retry count. +func expectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) { + var err error + for i := 0; i < maxRetries; i++ { + err = fn() + if err == nil { + return + } + framework.Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err) + } + if err != nil { + debug.PrintStack() + } + gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...) +} + var _ = framework.KubeDescribe("Pods", func() { f := framework.NewDefaultFramework("pods") var podClient *framework.PodClient @@ -526,7 +543,7 @@ var _ = framework.KubeDescribe("Pods", func() { "FOOSERVICE_PORT_8765_TCP=", "FOOSERVICE_PORT_8765_TCP_ADDR=", } - framework.ExpectNoErrorWithRetries(func() error { + expectNoErrorWithRetries(func() error { return f.MatchContainerOutput(pod, containerName, expectedVars, gomega.ContainSubstring) }, maxRetries, "Container should have service environment variables set") }) diff --git a/test/e2e/framework/expect.go b/test/e2e/framework/expect.go index 32335165498e..07b2de070022 100644 --- a/test/e2e/framework/expect.go +++ b/test/e2e/framework/expect.go @@ -17,8 +17,6 @@ limitations under the License. package framework import ( - "runtime/debug" - "github.com/onsi/gomega" ) @@ -47,19 +45,3 @@ func ExpectNoError(err error, explain ...interface{}) { func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) { gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...) } - -// ExpectNoErrorWithRetries checks if an error occurs with the given retry count. -func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) { - var err error - for i := 0; i < maxRetries; i++ { - err = fn() - if err == nil { - return - } - Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err) - } - if err != nil { - debug.PrintStack() - } - gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...) -} diff --git a/test/e2e/framework/pod/resource.go b/test/e2e/framework/pod/resource.go index 3d007ec0a4ff..9787104bbd5d 100644 --- a/test/e2e/framework/pod/resource.go +++ b/test/e2e/framework/pod/resource.go @@ -42,7 +42,6 @@ import ( ) // TODO: Move to its own subpkg. -// expectNoErrorWithRetries to their own subpackages within framework. // 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...)