-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcaller_test.go
98 lines (72 loc) · 1.77 KB
/
caller_test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package docs
import (
"math/rand"
"reflect"
"testing"
"testing/quick"
)
const testingPostfix = "Testing"
func TestQuickUnitCaller(t *testing.T) {
t.Parallel()
successParamNumber := func(i int, oas *OAS) {}
config := quick.Config{
Values: func(args []reflect.Value, rand *rand.Rand) {
rr := make(RegRoutes)
count := rand.Intn(550-1) + 1
paths := getPaths(t, count, RandomString(t, count))
for i := 0; i < count; i++ {
rr[paths[0].Route+testingPostfix] = successParamNumber
}
oas := OAS{
Paths: paths,
RegisteredRoutes: rr,
}
args[0] = reflect.ValueOf(oas)
},
}
callerCorrectParamNumber := func(oas OAS) bool {
for i, oasPath := range oas.Paths {
res := oas.Call(oasPath.Route+testingPostfix, i, &oas)
if len(res) > 0 {
t.Error("failed executing (OAS).Call() with")
return false
}
}
return true
}
if err := quick.Check(callerCorrectParamNumber, &config); err != nil {
t.Errorf("Check failed: %#v", err)
}
}
func TestUnitCaller(t *testing.T) {
t.Parallel()
successParamNumber := func(i int, oas *OAS) {}
routeName := "testRouteTesting"
rr := make(RegRoutes)
rr[routeName] = successParamNumber
o := OAS{
RegisteredRoutes: rr,
}
_ = o.Call(routeName, 0, &o)
}
func TestUnitInitCallStack(t *testing.T) {
t.Parallel()
o := prepForInitCallStack(t)
o.initCallStackForRoutes()
}
func prepForInitCallStack(t *testing.T) OAS {
t.Helper()
routeName := "testRoute" + routePostfix
rr := make(RegRoutes)
rr[routeName] = getSuccessParamNumber
path := Path{
HandlerFuncName: "testRoute",
}
o := OAS{
Paths: Paths{path},
RegisteredRoutes: rr,
}
return o
}
func getSuccessParamNumber(_ int, _ *OAS) {}
// func getFailureParamNumber(t *testing.T, _ int, _ *OAS) { t.Helper() }