-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbast_test.go
79 lines (59 loc) · 1.11 KB
/
bast_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
//Copyright 2018 The axx Authors. All rights reserved.
package bast
import (
"testing"
"time"
"github.com/axfor/bast/httpc"
)
var appStarted bool
func Benchmark_QPS(t *testing.B) {
if !appStarted {
startApp()
}
t.ResetTimer()
t.ReportAllocs()
t.RunParallel(func(pb *testing.PB) {
for pb.Next() {
r, err := httpc.Get("http://127.0.0.1:9999/bast").Param("n", t.N).String()
if err != nil || r == "" {
t.Error(err)
}
}
})
}
func TestBastApp(t *testing.T) {
t.Cleanup(exitApp)
startApp()
ok := httpc.Get("http://127.0.0.1:9999/bast").OK()
if !ok {
t.FailNow()
}
ok = httpc.Post("http://127.0.0.1:9999/bast").OK()
if !ok {
t.FailNow()
}
ok = httpc.Put("http://127.0.0.1:9999/bast").OK()
if !ok {
t.FailNow()
}
}
func startApp() {
appStarted = true
go Run(":9999")
time.Sleep(time.Second)
}
func init() {
Get("/bast", func(ctx *Context) {
ctx.Says("hello bast of get")
})
Post("/bast", func(ctx *Context) {
ctx.Says("hello bast of post")
})
Put("/bast", func(ctx *Context) {
ctx.Says("hello bast of put")
})
}
func exitApp() {
appStarted = false
Shutdown(nil)
}