-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
44 lines (37 loc) · 1010 Bytes
/
server_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
package main
import (
"net/http/httptest"
"testing"
)
func TestServeHTTP(t *testing.T) {
// Init config
_publicPath = "_example/public"
_templatesPath = "_example/templates"
// Init handler
h := thtmlHandler{}
// Test requests
resp := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/index.html", nil)
h.ServeHTTP(resp, req)
if resp.Code != 200 {
t.Fatalf("Expected response code 200. Got %d", resp.Code)
}
resp = httptest.NewRecorder()
req = httptest.NewRequest("GET", "/index", nil)
h.ServeHTTP(resp, req)
if resp.Code != 200 {
t.Fatalf("Expected response code 200. Got %d", resp.Code)
}
resp = httptest.NewRecorder()
req = httptest.NewRequest("GET", "/", nil)
h.ServeHTTP(resp, req)
if resp.Code != 200 {
t.Fatalf("Expected response code 200. Got %d", resp.Code)
}
resp = httptest.NewRecorder()
req = httptest.NewRequest("GET", "/not-found", nil)
h.ServeHTTP(resp, req)
if resp.Code != 404 {
t.Fatalf("Expected response code 404. Got %d", resp.Code)
}
}