-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_test.go
More file actions
48 lines (43 loc) · 1.08 KB
/
api_test.go
File metadata and controls
48 lines (43 loc) · 1.08 KB
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
package main
import (
"github.com/ant0ine/go-json-rest/rest"
"github.com/ant0ine/go-json-rest/rest/test"
"log"
"testing"
)
func TestPostEvent(t *testing.T) {
i := Impl{}
i.InitDB()
i.InitSchema()
api := rest.NewApi()
api.Use(rest.DefaultDevStack...)
router, err := rest.MakeRouter(
rest.Post("/events", i.PostEvent),
)
if err != nil {
log.Fatal(err)
}
api.SetApp(router)
recorded := test.RunRequest(t, api.MakeHandler(),
test.MakeSimpleRequest("POST", "http://1.2.3.4/events", &map[string]string{"measurement": "stress"}))
recorded.CodeIs(201)
recorded.ContentTypeIsJson()
}
func TestPostInstallation(t *testing.T) {
i := Impl{}
i.InitDB()
i.InitSchema()
api := rest.NewApi()
api.Use(rest.DefaultDevStack...)
router, err := rest.MakeRouter(
rest.Post("/installations", i.PostInstallation),
)
if err != nil {
log.Fatal(err)
}
api.SetApp(router)
recorded := test.RunRequest(t, api.MakeHandler(),
test.MakeSimpleRequest("POST", "http://1.2.3.4/installations", &map[string]string{"deviceType": "android"}))
recorded.CodeIs(201)
recorded.ContentTypeIsJson()
}