mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-30 12:01:29 +00:00
Add unit tests for gzip
This commit is contained in:
parent
20a9c66286
commit
f8cb20ade6
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
. "gopkg.in/check.v1"
|
||||
|
||||
gzipp "compress/gzip"
|
||||
jpegp "image/jpeg"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -41,7 +42,11 @@ func (s *CompyTest) SetUpSuite(c *C) {
|
|||
}()
|
||||
|
||||
proxyUrl := &url.URL{Scheme: "http", Host: "localhost" + *host}
|
||||
s.client = &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||
tr := &http.Transport{
|
||||
DisableCompression: true,
|
||||
Proxy: http.ProxyURL(proxyUrl),
|
||||
}
|
||||
s.client = &http.Client{Transport: tr}
|
||||
}
|
||||
|
||||
func (s *CompyTest) TearDownSuite(c *C) {
|
||||
|
@ -56,6 +61,32 @@ func (s *CompyTest) TestHttpBin(c *C) {
|
|||
c.Assert(resp.StatusCode, Equals, 200)
|
||||
}
|
||||
|
||||
func (s *CompyTest) TestNoGzip(c *C) {
|
||||
resp, err := http.Get(s.server.URL + "/html")
|
||||
c.Assert(err, IsNil)
|
||||
defer resp.Body.Close()
|
||||
c.Assert(resp.StatusCode, Equals, 200)
|
||||
c.Assert(resp.Header.Get("Content-Encoding"), Equals, "")
|
||||
|
||||
_, err = gzipp.NewReader(resp.Body)
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *CompyTest) TestGzip(c *C) {
|
||||
req, err := http.NewRequest("GET", s.server.URL+"/html", nil)
|
||||
c.Assert(err, IsNil)
|
||||
req.Header.Add("Accept-Encoding", "gzip")
|
||||
|
||||
resp, err := s.client.Do(req)
|
||||
c.Assert(err, IsNil)
|
||||
defer resp.Body.Close()
|
||||
c.Assert(resp.StatusCode, Equals, 200)
|
||||
c.Assert(resp.Header.Get("Content-Encoding"), Equals, "gzip")
|
||||
|
||||
_, err = gzipp.NewReader(resp.Body)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *CompyTest) TestJpeg(c *C) {
|
||||
req, err := http.NewRequest("GET", s.server.URL+"/image/jpeg", nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
|
Loading…
Reference in a new issue