-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
37 lines (32 loc) · 743 Bytes
/
main_test.go
File metadata and controls
37 lines (32 loc) · 743 Bytes
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
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
)
func TestMain(m *testing.M) {
main()
os.Exit(m.Run())
}
func TestNext(t *testing.T) {
resp := httptest.NewRecorder()
uri := "http://localhost:5001/next/NB/Redwood%20City%20Caltrain"
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
t.Fatal(err)
}
//t.Logf("req: %s", req.)
http.DefaultServeMux.ServeHTTP(resp, req)
if p, err := ioutil.ReadAll(resp.Body); err != nil {
t.Fail()
} else {
if strings.Contains(string(p), "Error") {
t.Errorf("header response shouldn't return error: %s", p)
} else if !strings.Contains(string(p), `expected result`) {
t.Errorf("header response doen't match:\n%s", p)
}
}
}