-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaults_test.go
47 lines (34 loc) · 1.03 KB
/
defaults_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
46
47
package kid
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func setupKid() *Kid {
k := New()
k.Post("/post", func(c *Context) {
c.JSON(http.StatusOK, Map{"method": c.Request().Method})
})
return k
}
func TestDefaultNotFoundHandler(t *testing.T) {
k := setupKid()
w := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "/not-found", nil)
assert.NoError(t, err)
k.ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, "{\"message\":\"Not Found\"}\n", w.Body.String())
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
}
func TestDefaultMethodNotAllowedHandler(t *testing.T) {
k := setupKid()
w := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "/post", nil)
assert.NoError(t, err)
k.ServeHTTP(w, req)
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
assert.Equal(t, "{\"message\":\"Method Not Allowed\"}\n", w.Body.String())
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
}