-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathmain_test.go
More file actions
33 lines (26 loc) · 718 Bytes
/
main_test.go
File metadata and controls
33 lines (26 loc) · 718 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
// Test the main function
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestMain(t *testing.T) {
req, err := http.NewRequest("GET", "/home", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(homePage)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
// Just verify the code not html content
expected := "text/html; charset=utf-8"
if contentType := rr.Header().Get("Content-Type"); contentType != expected {
t.Errorf("handler returned unexpected content type: got %v want %v",
contentType, expected)
}
}