-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjson_test.go
More file actions
28 lines (24 loc) · 799 Bytes
/
json_test.go
File metadata and controls
28 lines (24 loc) · 799 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
package response
import "github.com/bmizerany/assert"
import "net/http/httptest"
import "testing"
type User struct {
First string `json:"first"`
Last string `json:"last"`
}
func TestJSONPretty(t *testing.T) {
Pretty = true
res := httptest.NewRecorder()
JSON(res, &User{"Tobi", "Ferret"})
assert.Equal(t, 200, res.Code)
assert.Equal(t, "{\n \"first\": \"Tobi\",\n \"last\": \"Ferret\"\n}", string(res.Body.Bytes()))
assert.Equal(t, "application/json", res.HeaderMap["Content-Type"][0])
}
func TestJSON(t *testing.T) {
Pretty = false
res := httptest.NewRecorder()
JSON(res, &User{"Tobi", "Ferret"})
assert.Equal(t, 200, res.Code)
assert.Equal(t, `{"first":"Tobi","last":"Ferret"}`, string(res.Body.Bytes()))
assert.Equal(t, "application/json", res.HeaderMap["Content-Type"][0])
}