add some tests for the content type for the embedding files and gziped embedded files

Former-commit-id: b7fe470f33efcdf70df3e41ad880bbd4704cbb4a
This commit is contained in:
Gerasimos Maropoulos 2018-03-15 23:09:07 +02:00
parent 2d8652d7fb
commit 89022c7051
3 changed files with 50 additions and 0 deletions

View File

@ -12,6 +12,24 @@ import (
type resource string
// content types that are used in the ./assets,
// we could use the detectContentType that iris do but it's better
// to do it manually so we can test if that returns the correct result on embedding files.
func (r resource) contentType() string {
switch filepath.Ext(r.String()) {
case ".js":
return "application/javascript"
case ".css":
return "text/css"
case ".ico":
return "image/x-icon"
case ".html":
return "text/html"
default:
return "text/plain"
}
}
func (r resource) String() string {
return string(r)
}
@ -66,6 +84,7 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
e.GET(url).Expect().
Status(httptest.StatusOK).
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
Body().Equal(contents)
}
}

View File

@ -14,6 +14,24 @@ import (
type resource string
// content types that are used in the ./assets,
// we could use the detectContentType that iris do but it's better
// to do it manually so we can test if that returns the correct result on embedding files.
func (r resource) contentType() string {
switch filepath.Ext(r.String()) {
case ".js":
return "application/javascript"
case ".css":
return "text/css"
case ".ico":
return "image/x-icon"
case ".html":
return "text/html"
default:
return "text/plain"
}
}
func (r resource) String() string {
return string(r)
}
@ -66,6 +84,7 @@ func TestEmbeddingGzipFilesIntoApp(t *testing.T) {
rawContents := u.loadFromBase("./assets")
response := e.GET(url).Expect()
response.ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset())
if expected, got := response.Raw().StatusCode, httptest.StatusOK; expected != got {
t.Fatalf("[%d] of '%s': expected %d status code but got %d", i, url, expected, got)

View File

@ -12,6 +12,17 @@ import (
type resource string
func (r resource) contentType() string {
switch filepath.Ext(r.String()) {
case ".js":
return "application/javascript"
case ".css":
return "text/css"
default:
return "text/html"
}
}
func (r resource) String() string {
return string(r)
}
@ -59,6 +70,7 @@ func TestSPAEmbedded(t *testing.T) {
e.GET(url).Expect().
Status(httptest.StatusOK).
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
Body().Equal(contents)
}
}