Skip to content

Commit

Permalink
Merge pull request #1722 from aldas/revert_pr_1674
Browse files Browse the repository at this point in the history
Revert #1674 - failing tests
  • Loading branch information
lammel authored Dec 17, 2020
2 parents ea31edb + 547ca5c commit 829e821
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 78 deletions.
1 change: 0 additions & 1 deletion echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl
}
return c.File(name)
}
get(prefix, h)
if prefix == "/" {
return get(prefix+"*", h)
}
Expand Down
43 changes: 0 additions & 43 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ func TestEchoStatic(t *testing.T) {
expectHeaderLocation: "/folder/",
expectBodyStartsWith: "",
},
{
name: "Directory Redirect with non-root path",
givenPrefix: "/static",
givenRoot: "_fixture",
whenURL: "/static",
expectStatus: http.StatusMovedPermanently,
expectHeaderLocation: "/static/",
expectBodyStartsWith: "",
},
{
name: "Directory with index.html",
givenPrefix: "/",
Expand Down Expand Up @@ -170,40 +161,6 @@ func TestEchoStatic(t *testing.T) {
}
}

func TestEchoStaticRedirectIndex(t *testing.T) {
assert := assert.New(t)
e := New()

// HandlerFunc
e.Static("/static", "_fixture")

errCh := make(chan error)

go func() {
errCh <- e.Start("127.0.0.1:1323")
}()

time.Sleep(200 * time.Millisecond)

if resp, err := http.Get("http://127.0.0.1:1323/static"); err == nil {
defer resp.Body.Close()
assert.Equal(http.StatusOK, resp.StatusCode)

if body, err := ioutil.ReadAll(resp.Body); err == nil {
assert.Equal(true, strings.HasPrefix(string(body), "<!doctype html>"))
} else {
assert.Fail(err.Error())
}

} else {
assert.Fail(err.Error())
}

if err := e.Close(); err != nil {
t.Fatal(err)
}
}

func TestEchoFile(t *testing.T) {
e := New()
e.File("/walle", "_fixture/images/walle.png")
Expand Down
4 changes: 4 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
if len(g.middleware) == 0 {
return
}
// Allow all requests to reach the group as they might get dropped if router
// doesn't find a match, making none of the group middleware process.
g.Any("", NotFoundHandler)
g.Any("/*", NotFoundHandler)
}

// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
Expand Down
34 changes: 0 additions & 34 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,3 @@ func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) {
assert.Equal(t, "/*", m)

}

func TestMultipleGroupSamePathMiddleware(t *testing.T) {
// Ensure multiple groups with the same path do not clobber previous routes or mixup middlewares
e := New()
m1 := func(next HandlerFunc) HandlerFunc {
return func(c Context) error {
c.Set("middleware", "m1")
return next(c)
}
}
m2 := func(next HandlerFunc) HandlerFunc {
return func(c Context) error {
c.Set("middleware", "m2")
return next(c)
}
}
h := func(c Context) error {
return c.String(http.StatusOK, c.Get("middleware").(string))
}

g1 := e.Group("/group", m1)
{
g1.GET("", h)
}
g2 := e.Group("/group", m2)
{
g2.GET("/other", h)
}

_, m := request(http.MethodGet, "/group", e)
assert.Equal(t, "m1", m)
_, m = request(http.MethodGet, "/group/other", e)
assert.Equal(t, "m2", m)
}

0 comments on commit 829e821

Please # to comment.