forked from Rosalita/GoViolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome_test.go
27 lines (21 loc) · 793 Bytes
/
home_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
package main
import (
"net/http/httptest"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHomePage(t *testing.T) {
// Create a request to pass to handler
r, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
// Create a new responserecorder (which satisfies http.ResponseWriter) to record the response
rr := httptest.NewRecorder()
handler := http.HandlerFunc(Home)
// Handlers satisfy http.Handler, so can call their ServeHTTP method directly to pass in the request and responserecorder.
handler.ServeHTTP(rr, r)
// assert status code of response recorder is OK
assert.Equal(t, rr.Code, http.StatusOK, "HandlerFunc(Home) returned wrong status code: got %v want %v", rr.Code, http.StatusOK)
}