-
Notifications
You must be signed in to change notification settings - Fork 34
/
acceptor_test.go
51 lines (40 loc) · 1.18 KB
/
acceptor_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
package main
import(
"net/http"
"net/http/httptest"
"testing"
"github.com/julienschmidt/httprouter"
)
// Test basic responder flow that returns hello world
func Test_GetHelloWorld(t *testing.T) {
router := httprouter.New()
router.GET("/_/*p", process)
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/_/test_string", nil)
_start_broker()
go _test_string_responder()
router.ServeHTTP(writer, request)
if writer.Code != 200 {
t.Errorf("Response code is %v", writer.Code)
}
if writer.Body.String() != "Hello World" {
t.Errorf("Body is %v", writer.Body)
}
}
// Test basic responder flow that returns a JSON string that it sends across
func Test_GetJSON(t *testing.T) {
router := httprouter.New()
router.GET("/_/*p", process)
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/_/test_json", nil)
_start_broker()
go _test_json_responder()
router.ServeHTTP(writer, request)
if writer.Code != 200 {
t.Errorf("Response code is %v", writer.Code)
}
sample_json := _read_sample_json()
if writer.Body.String() != sample_json {
t.Errorf("Body is %s", writer.Body)
}
}