mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #84410 from jfbai/move-funcs-of-expect-to-common
move funcs of expect.go to e2e/common
This commit is contained in:
commit
e86878436f
@ -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")
|
||||
})
|
||||
|
@ -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...)
|
||||
}
|
||||
|
@ -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...)
|
||||
|
Loading…
Reference in New Issue
Block a user