Skip to content

Commit 5782d61

Browse files
committed
Move skip method from e2e fw ginkgowrapper to e2e skipper fw
1 parent 6541758 commit 5782d61

File tree

4 files changed

+76
-42
lines changed

4 files changed

+76
-42
lines changed

test/e2e/cloud/gcp/cluster_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func finalizeUpgradeTest(start time.Time, tc *junit.TestCase) {
416416
Value: fmt.Sprintf("%s\n\n%s", r.Message, r.FullStackTrace),
417417
},
418418
}
419-
case ginkgowrapper.SkipPanic:
419+
case e2eskipper.SkipPanic:
420420
tc.Skipped = fmt.Sprintf("%s:%d %q", r.Filename, r.Line, r.Message)
421421
default:
422422
tc.Errors = []*junit.Error{

test/e2e/framework/ginkgowrapper/wrapper.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,44 +67,6 @@ func Fail(message string, callerSkip ...int) {
6767
ginkgo.Fail(message, skip)
6868
}
6969

70-
// SkipPanic is the value that will be panicked from Skip.
71-
type SkipPanic struct {
72-
Message string // The failure message passed to Fail
73-
Filename string // The filename that is the source of the failure
74-
Line int // The line number of the filename that is the source of the failure
75-
FullStackTrace string // A full stack trace starting at the source of the failure
76-
}
77-
78-
// String makes SkipPanic look like the old Ginkgo panic when printed.
79-
func (SkipPanic) String() string { return ginkgo.GINKGO_PANIC }
80-
81-
// Skip wraps ginkgo.Skip so that it panics with more useful
82-
// information about why the test is being skipped. This function will
83-
// panic with a SkipPanic.
84-
func Skip(message string, callerSkip ...int) {
85-
skip := 1
86-
if len(callerSkip) > 0 {
87-
skip += callerSkip[0]
88-
}
89-
90-
_, file, line, _ := runtime.Caller(skip)
91-
sp := SkipPanic{
92-
Message: message,
93-
Filename: file,
94-
Line: line,
95-
FullStackTrace: pruneStack(skip),
96-
}
97-
98-
defer func() {
99-
e := recover()
100-
if e != nil {
101-
panic(sp)
102-
}
103-
}()
104-
105-
ginkgo.Skip(message, skip)
106-
}
107-
10870
// ginkgo adds a lot of test running infrastructure to the stack, so
10971
// we filter those out
11072
var stackSkipPattern = regexp.MustCompile(`onsi/ginkgo`)

test/e2e/framework/skipper/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ go_library(
1616
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
1717
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
1818
"//test/e2e/framework:go_default_library",
19-
"//test/e2e/framework/ginkgowrapper:go_default_library",
2019
"//test/e2e/framework/ssh:go_default_library",
20+
"//vendor/github.com/onsi/ginkgo:go_default_library",
2121
],
2222
)
2323

test/e2e/framework/skipper/skipper.go

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ limitations under the License.
1717
package skipper
1818

1919
import (
20+
"bufio"
21+
"bytes"
2022
"fmt"
23+
"github.com/onsi/ginkgo"
24+
"regexp"
25+
"runtime"
26+
"runtime/debug"
27+
"strings"
2128

2229
apierrors "k8s.io/apimachinery/pkg/api/errors"
2330
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,7 +36,6 @@ import (
2936
clientset "k8s.io/client-go/kubernetes"
3037
"k8s.io/kubernetes/pkg/features"
3138
"k8s.io/kubernetes/test/e2e/framework"
32-
"k8s.io/kubernetes/test/e2e/framework/ginkgowrapper"
3339
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
3440
)
3541

@@ -39,7 +45,73 @@ var TestContext framework.TestContextType
3945
func skipInternalf(caller int, format string, args ...interface{}) {
4046
msg := fmt.Sprintf(format, args...)
4147
framework.Logf("INFO", msg)
42-
ginkgowrapper.Skip(msg, caller+1)
48+
skip(msg, caller+1)
49+
}
50+
51+
// SkipPanic is the value that will be panicked from Skip.
52+
type SkipPanic struct {
53+
Message string // The failure message passed to Fail
54+
Filename string // The filename that is the source of the failure
55+
Line int // The line number of the filename that is the source of the failure
56+
FullStackTrace string // A full stack trace starting at the source of the failure
57+
}
58+
59+
// String makes SkipPanic look like the old Ginkgo panic when printed.
60+
func (SkipPanic) String() string { return ginkgo.GINKGO_PANIC }
61+
62+
// Skip wraps ginkgo.Skip so that it panics with more useful
63+
// information about why the test is being skipped. This function will
64+
// panic with a SkipPanic.
65+
func skip(message string, callerSkip ...int) {
66+
skip := 1
67+
if len(callerSkip) > 0 {
68+
skip += callerSkip[0]
69+
}
70+
71+
_, file, line, _ := runtime.Caller(skip)
72+
sp := SkipPanic{
73+
Message: message,
74+
Filename: file,
75+
Line: line,
76+
FullStackTrace: pruneStack(skip),
77+
}
78+
79+
defer func() {
80+
e := recover()
81+
if e != nil {
82+
panic(sp)
83+
}
84+
}()
85+
86+
ginkgo.Skip(message, skip)
87+
}
88+
89+
// ginkgo adds a lot of test running infrastructure to the stack, so
90+
// we filter those out
91+
var stackSkipPattern = regexp.MustCompile(`onsi/ginkgo`)
92+
93+
func pruneStack(skip int) string {
94+
skip += 2 // one for pruneStack and one for debug.Stack
95+
stack := debug.Stack()
96+
scanner := bufio.NewScanner(bytes.NewBuffer(stack))
97+
var prunedStack []string
98+
99+
// skip the top of the stack
100+
for i := 0; i < 2*skip+1; i++ {
101+
scanner.Scan()
102+
}
103+
104+
for scanner.Scan() {
105+
if stackSkipPattern.Match(scanner.Bytes()) {
106+
scanner.Scan() // these come in pairs
107+
} else {
108+
prunedStack = append(prunedStack, scanner.Text())
109+
scanner.Scan() // these come in pairs
110+
prunedStack = append(prunedStack, scanner.Text())
111+
}
112+
}
113+
114+
return strings.Join(prunedStack, "\n")
43115
}
44116

45117
// Skipf skips with information about why the test is being skipped.

0 commit comments

Comments
 (0)