-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_test.go
36 lines (28 loc) · 855 Bytes
/
error_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
package gohm_test
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/karrick/gohm"
)
// when error called, status updated, client receives message
func TestWhenErrorInvoked(t *testing.T) {
recorder := httptest.NewRecorder()
request := httptest.NewRequest("GET", "/some/url", nil)
handler := gohm.New(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gohm.Error(w, "some error", http.StatusForbidden)
}), gohm.Config{})
handler.ServeHTTP(recorder, request)
resp := recorder.Result()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if got, want := resp.StatusCode, http.StatusForbidden; got != want {
t.Errorf("GOT: %v; WANT: %v", got, want)
}
if got, want := string(body), "403 Forbidden: some error\n"; got != want {
t.Errorf("GOT: %v; WANT: %v", got, want)
}
}