-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
46 lines (36 loc) · 874 Bytes
/
main_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
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func Test_Routes(t *testing.T) {
tests := []struct {
name string
request string
route string
body string
}{
{"main page", "/", rootRt, "gwbasic.wasm"},
}
for _, tt := range tests {
rq, err := http.NewRequest("GET", tt.request, nil)
if err != nil {
t.Fatal(err)
}
rtr := startup()
rr := httptest.NewRecorder()
hd := rtr.Get(tt.name).GetHandler()
hd.ServeHTTP(rr, rq)
if rr.Code != http.StatusOK {
t.Errorf("handler returned unexpected status code, got %v wanted %v\n", rr.Code, http.StatusOK)
}
body := rr.Body.String()
// I get back the html file so to check it
// I go looking for the refererence to the wasm file
if !strings.Contains(body, tt.body) {
t.Errorf("returned body did not contain %s, %s\n", tt.body, body)
}
}
}