add tests to verify gzip compression headers

pull/1514/head
Cory LaNou 2015-02-04 17:51:10 -07:00
parent 8845a07876
commit 727f7d1ed5
1 changed files with 48 additions and 0 deletions

View File

@ -480,6 +480,54 @@ func TestHandler_DeleteRetentionPolicy_NotFound(t *testing.T) {
}
}
func TestHandler_GzipEnabled(t *testing.T) {
srvr := OpenServer(NewMessagingClient())
s := NewHTTPServer(srvr)
defer s.Close()
req, err := http.NewRequest("GET", s.URL+`/ping`, bytes.NewBuffer([]byte{}))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept-Encoding", "gzip")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if ce := resp.Header.Get("Content-Encoding"); ce != "gzip" {
t.Fatalf("unexpected Content-Encoding. expected %q, actual: %q", "gzip", ce)
}
}
func TestHandler_GzipDisabled(t *testing.T) {
srvr := OpenServer(NewMessagingClient())
s := NewHTTPServer(srvr)
defer s.Close()
req, err := http.NewRequest("GET", s.URL+`/ping`, bytes.NewBuffer([]byte{}))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept-Encoding", "")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if ce := resp.Header.Get("Content-Encoding"); ce == "gzip" {
t.Fatalf("unexpected Content-Encoding. expected %q, actual: %q", "", ce)
}
}
func TestHandler_Ping(t *testing.T) {
srvr := OpenServer(NewMessagingClient())
s := NewHTTPServer(srvr)