mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 05:26:26 +01:00
add some tests for the content type for the embedding files and gziped embedded files
Former-commit-id: b7fe470f33efcdf70df3e41ad880bbd4704cbb4a
This commit is contained in:
parent
2d8652d7fb
commit
89022c7051
|
@ -12,6 +12,24 @@ import (
|
||||||
|
|
||||||
type resource string
|
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 {
|
func (r resource) String() string {
|
||||||
return string(r)
|
return string(r)
|
||||||
}
|
}
|
||||||
|
@ -66,6 +84,7 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
|
||||||
|
|
||||||
e.GET(url).Expect().
|
e.GET(url).Expect().
|
||||||
Status(httptest.StatusOK).
|
Status(httptest.StatusOK).
|
||||||
|
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||||
Body().Equal(contents)
|
Body().Equal(contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,24 @@ import (
|
||||||
|
|
||||||
type resource string
|
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 {
|
func (r resource) String() string {
|
||||||
return string(r)
|
return string(r)
|
||||||
}
|
}
|
||||||
|
@ -66,6 +84,7 @@ func TestEmbeddingGzipFilesIntoApp(t *testing.T) {
|
||||||
rawContents := u.loadFromBase("./assets")
|
rawContents := u.loadFromBase("./assets")
|
||||||
|
|
||||||
response := e.GET(url).Expect()
|
response := e.GET(url).Expect()
|
||||||
|
response.ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset())
|
||||||
|
|
||||||
if expected, got := response.Raw().StatusCode, httptest.StatusOK; expected != got {
|
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)
|
t.Fatalf("[%d] of '%s': expected %d status code but got %d", i, url, expected, got)
|
||||||
|
|
|
@ -12,6 +12,17 @@ import (
|
||||||
|
|
||||||
type resource string
|
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 {
|
func (r resource) String() string {
|
||||||
return string(r)
|
return string(r)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +70,7 @@ func TestSPAEmbedded(t *testing.T) {
|
||||||
|
|
||||||
e.GET(url).Expect().
|
e.GET(url).Expect().
|
||||||
Status(httptest.StatusOK).
|
Status(httptest.StatusOK).
|
||||||
|
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||||
Body().Equal(contents)
|
Body().Equal(contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user