transfer.sh/vendor/github.com/PuerkitoBio/ghost/handlers/static_test.go
Remco cb6e5cb0c7 Major rewrite
* use dep for vendoring
* lets encrypt
* moved web to transfer.sh-web repo
* single command install
* added first tests
2017-03-22 18:09:21 +01:00

46 lines
1 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestServeFile(t *testing.T) {
h := StaticFileHandler("./testdata/styles.css")
s := httptest.NewServer(h)
defer s.Close()
res, err := http.Get(s.URL)
if err != nil {
panic(err)
}
assertStatus(http.StatusOK, res.StatusCode, t)
assertHeader("Content-Type", "text/css; charset=utf-8", res, t)
assertHeader("Content-Encoding", "", res, t)
assertBody([]byte(`* {
background-color: white;
}`), res, t)
}
func TestGzippedFile(t *testing.T) {
h := GZIPHandler(StaticFileHandler("./testdata/styles.css"), nil)
s := httptest.NewServer(h)
defer s.Close()
req, err := http.NewRequest("GET", s.URL, nil)
if err != nil {
panic(err)
}
req.Header.Set("Accept-Encoding", "*")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
assertStatus(http.StatusOK, res.StatusCode, t)
assertHeader("Content-Encoding", "gzip", res, t)
assertHeader("Content-Type", "text/css; charset=utf-8", res, t)
assertGzippedBody([]byte(`* {
background-color: white;
}`), res, t)
}