forked from ant0ine/go-json-rest
/
gzip_test.go
38 lines (33 loc) · 919 Bytes
/
gzip_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
package rest
import (
"github.com/ant0ine/go-json-rest/test"
"testing"
)
func TestGzip(t *testing.T) {
handler := ResourceHandler{
DisableJsonIndent: true,
EnableGzip: true,
}
handler.SetRoutes(
Route{"GET", "/ok",
func(w *ResponseWriter, r *Request) {
w.WriteJson(map[string]string{"Id": "123"})
},
},
Route{"GET", "/error",
func(w *ResponseWriter, r *Request) {
Error(w, "gzipped error", 500)
},
},
)
recorded := test.RunRequest(t, &handler, test.MakeSimpleRequest("GET", "http://1.2.3.4/ok", nil))
recorded.CodeIs(200)
recorded.ContentTypeIsJson()
recorded.ContentEncodingIsGzip()
recorded.HeaderIs("Vary", "Accept-Encoding")
recorded = test.RunRequest(t, &handler, test.MakeSimpleRequest("GET", "http://1.2.3.4/error", nil))
recorded.CodeIs(500)
recorded.ContentTypeIsJson()
recorded.ContentEncodingIsGzip()
recorded.HeaderIs("Vary", "Accept-Encoding")
}