mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-23 16:41:30 +00:00
Add unit test for GIF transcoding
This commit is contained in:
parent
3760bb0a61
commit
a6bb5e3308
|
@ -3,7 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
|
|
||||||
|
"bytes"
|
||||||
gzipp "compress/gzip"
|
gzipp "compress/gzip"
|
||||||
|
gifp "image/gif"
|
||||||
jpegp "image/jpeg"
|
jpegp "image/jpeg"
|
||||||
pngp "image/png"
|
pngp "image/png"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -35,6 +37,7 @@ func (s *CompyTest) SetUpSuite(c *C) {
|
||||||
s.server = httptest.NewServer(httpbin.GetMux())
|
s.server = httptest.NewServer(httpbin.GetMux())
|
||||||
|
|
||||||
s.proxy = proxy.New()
|
s.proxy = proxy.New()
|
||||||
|
s.proxy.AddTranscoder("image/gif", &tc.Gif{})
|
||||||
s.proxy.AddTranscoder("image/jpeg", tc.NewJpeg(50))
|
s.proxy.AddTranscoder("image/jpeg", tc.NewJpeg(50))
|
||||||
s.proxy.AddTranscoder("image/png", &tc.Png{})
|
s.proxy.AddTranscoder("image/png", &tc.Png{})
|
||||||
s.proxy.AddTranscoder("text/html", &tc.Zip{&tc.Identity{}, *brotli, *gzip, true})
|
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)
|
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) {
|
func (s *CompyTest) TestJpeg(c *C) {
|
||||||
resp, err := s.client.Get(s.server.URL + "/image/jpeg")
|
resp, err := s.client.Get(s.server.URL + "/image/jpeg")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
Loading…
Reference in a new issue