-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboilerplate_test.go
58 lines (42 loc) · 1.13 KB
/
boilerplate_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
package webfmwk
import (
"testing"
"github.com/burgesQ/gommon/webtest"
"github.com/stretchr/testify/require"
)
const (
_testPort = ":6666"
_testAddr = "http://127.0.0.1" + _testPort
)
//
// helpers methods
//
func wrapperPost(t *testing.T, route, routeReq string,
content []byte,
handlerRoute HandlerFunc, handlerTest webtest.HandlerForTest,
) {
t.Helper()
s, e := InitServer(CheckIsUp())
require.Nil(t, e)
t.Cleanup(func() { require.Nil(t, s.ShutdownAndWait()) })
s.POST(route, handlerRoute)
go s.Start(_testPort)
<-s.isReady
webtest.PushAndTestAPI(t, _testAddr+routeReq, content, handlerTest)
}
func wrapperGet(t *testing.T, route, routeReq string,
handlerRoute HandlerFunc, handlerTest webtest.HandlerForTest,
) {
t.Helper()
s, e := InitServer(CheckIsUp())
require.Nil(t, e)
t.Log("server is created")
t.Cleanup(func() { require.Nil(t, s.ShutdownAndWait()) })
s.GET(route, handlerRoute)
t.Logf("starting server -- %q\n", route)
go s.Start(_testPort)
<-s.isReady
t.Log("server's ready")
t.Logf("requesting the API on %q\n", _testAddr+routeReq)
webtest.RequestAndTestAPI(t, _testAddr+routeReq, handlerTest)
}