-
Notifications
You must be signed in to change notification settings - Fork 3
/
status_test.go
29 lines (25 loc) · 1 KB
/
status_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
package response
import "github.com/bmizerany/assert"
import "net/http/httptest"
import "testing"
func TestStatusFunctions(t *testing.T) {
res := httptest.NewRecorder()
NotFound(res)
assert.Equal(t, 404, res.Code)
assert.Equal(t, "Not Found\n", string(res.Body.Bytes()))
assert.Equal(t, "text/plain; charset=utf-8", res.HeaderMap["Content-Type"][0])
}
func TestStatusFunctionsMessage(t *testing.T) {
res := httptest.NewRecorder()
NotFound(res, "can't find that")
assert.Equal(t, 404, res.Code)
assert.Equal(t, "can't find that\n", string(res.Body.Bytes()))
assert.Equal(t, "text/plain; charset=utf-8", res.HeaderMap["Content-Type"][0])
}
func TestStatusFunctionsJSON(t *testing.T) {
res := httptest.NewRecorder()
Unauthorized(res, map[string]string{"error": "token_expired", "message": "Token expired!"})
assert.Equal(t, 401, res.Code)
assert.Equal(t, `{"error":"token_expired","message":"Token expired!"}`, string(res.Body.Bytes()))
assert.Equal(t, "application/json", res.HeaderMap["Content-Type"][0])
}