-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
47 lines (37 loc) · 931 Bytes
/
api.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
// Package api provides testing facilities for the api package
package api
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gorilla/mux"
"github.com/lanets/floorplanets/backend/api"
"github.com/lanets/floorplanets/backend/app"
test_app "github.com/lanets/floorplanets/backend/tests/app"
)
// ApiTest simulates an http API
type ApiTest struct {
router *mux.Router
testApp *test_app.TestApp
t *testing.T
}
func NewApiTest(t *testing.T) *ApiTest {
testApp := test_app.NewTestApp(t)
apiTest := ApiTest{
router: api.NewRouter(testApp.App),
testApp: testApp,
t: t,
}
return &apiTest
}
func (apiTest *ApiTest) ServeHTTP(req *http.Request) *httptest.ResponseRecorder {
res := httptest.NewRecorder()
apiTest.router.ServeHTTP(res, req)
return res
}
func (apiTest *ApiTest) Close() {
apiTest.testApp.Close()
}
func (apiTest *ApiTest) App() *app.App {
return apiTest.testApp.App
}