1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 02:47:04 +00:00
Former-commit-id: 2b5ae1857a5815977507b6b8fc72dd0040d470ca
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-29 21:16:43 +03:00
parent ac08f53ba0
commit 714e84b597
7 changed files with 40 additions and 16 deletions

View File

@@ -9,8 +9,6 @@ import (
"github.com/kataras/iris/v12/httptest"
)
const prefixURL = "/v1"
type resource string
func (r resource) contentType() string {
@@ -37,10 +35,10 @@ func (r resource) strip(strip string) string {
return strings.TrimPrefix(s, strip)
}
func (r resource) loadFromBase(dir string) string {
func (r resource) loadFromBase(dir string, strip string) string {
filename := r.String()
filename = r.strip("/static")
filename = r.strip(strip)
if filepath.Ext(filename) == "" {
// root /.
filename = filename + "/index.html"
@@ -60,12 +58,12 @@ func (r resource) loadFromBase(dir string) string {
func TestFileServerBasic(t *testing.T) {
urls := []resource{
"/static/css/main.css",
"/static/js/jquery-2.1.1.js",
"/static/favicon.ico",
"/static/app2",
"/static/app2/app2app3",
"/static",
"/v1/static/css/main.css",
"/v1/static/js/jquery-2.1.1.js",
"/v1/static/favicon.ico",
"/v1/static/app2",
"/v1/static/app2/app2app3",
"/v1/static",
}
app := newApp()
@@ -85,9 +83,29 @@ func TestFileServerBasic(t *testing.T) {
e := httptest.New(t, app)
for _, u := range urls {
url := u.String()
contents := u.loadFromBase("./assets")
contents := u.loadFromBase("./assets", "/v1/static")
e.GET(prefixURL+url).Expect().
e.GET(url).Expect().
Status(httptest.StatusOK).
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
Body().Equal(contents)
}
}
// Tests subdomain + request path and system directory with a name that contains a dot(.)
func TestHandleDirDot(t *testing.T) {
urls := []resource{
"/v1/assets.system/css/main.css",
}
app := newApp()
app.Subdomain("test").Party("/v1").HandleDir("/assets.system", "./assets.system")
e := httptest.New(t, app, httptest.URL("http://test.example.com"))
for _, u := range urls {
url := u.String()
contents := u.loadFromBase("./assets.system", "/v1/assets.system")
e.GET(url).Expect().
Status(httptest.StatusOK).
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
Body().Equal(contents)