-
Notifications
You must be signed in to change notification settings - Fork 41
/
web_test.go
45 lines (35 loc) · 837 Bytes
/
web_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
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestMetricsHandler(t *testing.T) {
m := MetricList{Version: "1"}
a := appContext{nil, &m}
w := httptest.NewRecorder()
r := http.Request{}
status, _ := metricsHandler(&a, w, &r)
if status != 200 {
t.Error("Response should be successful")
}
if w.HeaderMap["Content-Type"][0] != "application/json" {
t.Error("Content-Type should be set to application/json")
}
v := MetricList{}
json.Unmarshal(w.Body.Bytes(), &v)
if v.Version != m.Version {
t.Errorf("Expected %v to be %v", v, m)
}
}
func TestAliasHandler(t *testing.T) {
w := httptest.NewRecorder()
r := http.Request{}
aliasHandler(w, &r)
bs, _ := Asset("index.html")
html := string(bs)
if w.Body.String() != html {
t.Error("Index page should be rendered")
}
}