@@ -17,7 +17,14 @@ limitations under the License.
17
17
package skipper
18
18
19
19
import (
20
+ "bufio"
21
+ "bytes"
20
22
"fmt"
23
+ "github.com/onsi/ginkgo"
24
+ "regexp"
25
+ "runtime"
26
+ "runtime/debug"
27
+ "strings"
21
28
22
29
apierrors "k8s.io/apimachinery/pkg/api/errors"
23
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -29,7 +36,6 @@ import (
29
36
clientset "k8s.io/client-go/kubernetes"
30
37
"k8s.io/kubernetes/pkg/features"
31
38
"k8s.io/kubernetes/test/e2e/framework"
32
- "k8s.io/kubernetes/test/e2e/framework/ginkgowrapper"
33
39
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
34
40
)
35
41
@@ -39,7 +45,73 @@ var TestContext framework.TestContextType
39
45
func skipInternalf (caller int , format string , args ... interface {}) {
40
46
msg := fmt .Sprintf (format , args ... )
41
47
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 " )
43
115
}
44
116
45
117
// Skipf skips with information about why the test is being skipped.
0 commit comments