mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Dump the stacktrace while an error occurs
Signed-off-by: Jiatong Wang <wangjiatong@vmware.com>
This commit is contained in:
parent
90df64b75b
commit
9a2ccc2c4f
@ -32,6 +32,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -1359,16 +1360,28 @@ func RandomSuffix() string {
|
||||
|
||||
// ExpectEqual expects the specified two are the same, otherwise an exception raises
|
||||
func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
||||
if isEqual, _ := gomega.Equal(extra).Match(actual); !isEqual {
|
||||
e2elog.Logf("Unexpected unequal occurred: %v and %v", actual, extra)
|
||||
debug.PrintStack()
|
||||
}
|
||||
gomega.Expect(actual).To(gomega.Equal(extra), explain...)
|
||||
}
|
||||
|
||||
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
|
||||
func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
||||
if isEqual, _ := gomega.Equal(extra).Match(actual); isEqual {
|
||||
e2elog.Logf("Expect to be unequal: %v and %v", actual, extra)
|
||||
debug.PrintStack()
|
||||
}
|
||||
gomega.Expect(actual).NotTo(gomega.Equal(extra), explain...)
|
||||
}
|
||||
|
||||
// ExpectError expects an error happens, otherwise an exception raises
|
||||
func ExpectError(err error, explain ...interface{}) {
|
||||
if err == nil {
|
||||
e2elog.Logf("Expect error to occur.")
|
||||
debug.PrintStack()
|
||||
}
|
||||
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
|
||||
}
|
||||
|
||||
@ -1382,6 +1395,7 @@ func ExpectNoError(err error, explain ...interface{}) {
|
||||
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
|
||||
if err != nil {
|
||||
e2elog.Logf("Unexpected error occurred: %v", err)
|
||||
debug.PrintStack()
|
||||
}
|
||||
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
|
||||
}
|
||||
@ -1396,6 +1410,9 @@ func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interf
|
||||
}
|
||||
e2elog.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...)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user