Add unit test for GIF transcoding

This commit is contained in:
Andrew Gaul 2017-01-21 15:04:07 -08:00
parent 3760bb0a61
commit a6bb5e3308

View file

@ -3,7 +3,9 @@ package main
import (
. "gopkg.in/check.v1"
"bytes"
gzipp "compress/gzip"
gifp "image/gif"
jpegp "image/jpeg"
pngp "image/png"
"io/ioutil"
@ -35,6 +37,7 @@ func (s *CompyTest) SetUpSuite(c *C) {
s.server = httptest.NewServer(httpbin.GetMux())
s.proxy = proxy.New()
s.proxy.AddTranscoder("image/gif", &tc.Gif{})
s.proxy.AddTranscoder("image/jpeg", tc.NewJpeg(50))
s.proxy.AddTranscoder("image/png", &tc.Png{})
s.proxy.AddTranscoder("text/html", &tc.Zip{&tc.Identity{}, *brotli, *gzip, true})
@ -111,6 +114,25 @@ func (s *CompyTest) TestBrotli(c *C) {
c.Assert(err, IsNil)
}
func (s *CompyTest) TestGif(c *C) {
resp, err := http.Get(s.server.URL + "/image/gif")
c.Assert(err, IsNil)
uncompressedLength, err := new(bytes.Buffer).ReadFrom(resp.Body)
c.Assert(err, IsNil)
resp.Body.Close()
resp, err = s.client.Get(s.server.URL + "/image/gif")
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, 200)
c.Assert(resp.Header.Get("Content-Type"), Equals, "image/gif")
_, err = gifp.Decode(resp.Body)
c.Assert(err, IsNil)
compressedLength := resp.ContentLength
c.Assert(uncompressedLength > compressedLength, Equals, true)
}
func (s *CompyTest) TestJpeg(c *C) {
resp, err := s.client.Get(s.server.URL + "/image/jpeg")
c.Assert(err, IsNil)