-
Notifications
You must be signed in to change notification settings - Fork 23
/
case.go
44 lines (38 loc) · 859 Bytes
/
case.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package test
import (
"testing"
"github.com/v2pro/plz/countlog"
"context"
"github.com/v2pro/plz/gls"
"reflect"
)
var testingTType = reflect.TypeOf((*testing.T)(nil))
func Case(testCase func(ctx *countlog.Context)) func(t *testing.T) {
return func(t *testing.T) {
goid := gls.GoID()
gls.ResetGls(goid, map[interface{}]interface{}{
testingTType: t,
})
ctx := countlog.Ctx(context.Background())
defer func() {
gls.DeleteGls(goid)
//if t.Failed() {
// ctx.LogAccess("test failed", errors.New(""))
//}
}()
testCase(ctx)
}
}
func Skip(args ...interface{}) {
CurrentT().Skip(args...)
}
func Skipf(format string, args ...interface{}) {
CurrentT().Skipf(format, args...)
}
func CurrentT() *testing.T {
t, found := gls.Get(testingTType).(*testing.T)
if !found {
panic("test not started with check.Case()")
}
return t
}