diff --git a/_examples/file-server/embedding-files-into-app/main_test.go b/_examples/file-server/embedding-files-into-app/main_test.go index 5369620d..cde4f11f 100644 --- a/_examples/file-server/embedding-files-into-app/main_test.go +++ b/_examples/file-server/embedding-files-into-app/main_test.go @@ -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) } } diff --git a/_examples/file-server/embedding-gziped-files-into-app/main_test.go b/_examples/file-server/embedding-gziped-files-into-app/main_test.go index 26499fc1..596ecc7f 100644 --- a/_examples/file-server/embedding-gziped-files-into-app/main_test.go +++ b/_examples/file-server/embedding-gziped-files-into-app/main_test.go @@ -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) diff --git a/_examples/file-server/single-page-application/embedded-single-page-application/main_test.go b/_examples/file-server/single-page-application/embedded-single-page-application/main_test.go index 2fe89b40..348be2ee 100644 --- a/_examples/file-server/single-page-application/embedded-single-page-application/main_test.go +++ b/_examples/file-server/single-page-application/embedded-single-page-application/main_test.go @@ -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) } }