diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-05 19:04:21 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-05 19:04:21 +0300 |
commit | b0ac2a7d3f7c48702120de4910cde34b7aee7bdd (patch) | |
tree | a8aaad3f80b5dcf51f2d3e8905d5da1172784c07 /domain_test.go | |
parent | 5c830cca6dee4ad6f0025dda14fa345bb677e38c (diff) |
Fix: Content-Type of predefined 404 pagev0.2.2
Diffstat (limited to 'domain_test.go')
-rw-r--r-- | domain_test.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/domain_test.go b/domain_test.go index d1dca06e..56e032a4 100644 --- a/domain_test.go +++ b/domain_test.go @@ -5,6 +5,9 @@ import ( "net/http" "net/url" "testing" + "net/http/httptest" + "github.com/stretchr/testify/require" + "mime" ) func TestGroupServeHTTP(t *testing.T) { @@ -48,14 +51,16 @@ func TestDomainServeHTTP(t *testing.T) { assert.HTTPError(t, testDomain.ServeHTTP, "GET", "/not-existing-file", nil) } -func testHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool { - if !assert.HTTPError(t, handler, mode, url, values) { - return false - } - if !assert.HTTPBodyContains(t, handler, mode, url, values, str) { - return false - } - return true +func testHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) { + w := httptest.NewRecorder() + req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil) + require.NoError(t, err) + handler(w, req) + + contentType, _, _ := mime.ParseMediaType(w.Header().Get("Content-Type")) + assert.Equal(t, http.StatusNotFound, w.Code, "HTTP status") + assert.Equal(t, "text/html", contentType, "Content-Type") + assert.Contains(t, w.Body.String(), str) } func TestGroup404ServeHTTP(t *testing.T) { |