Skip to content

Commit

Permalink
Merge pull request #487 from ReneWerner87/fix_group_routing
Browse files Browse the repository at this point in the history
fix the unnecessary pass through for routes with groups
  • Loading branch information
Fenny authored Jun 19, 2020
2 parents 20b2c82 + f1710ea commit 308ab66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ func Test_App_Group(t *testing.T) {
//utils.AssertEqual(t, "/test/v1/users", resp.Header.Get("Location"), "Location")
}

func Test_App_Deep_Group(t *testing.T) {
runThroughCount := 0
var dummyHandler = func(c *Ctx) {
runThroughCount++
c.Next()
}

app := New()
gApi := app.Group("/api", dummyHandler)
gV1 := gApi.Group("/v1", dummyHandler)
gUser := gV1.Group("/user", dummyHandler)
gUser.Get("/authenticate", func(ctx *Ctx) {
runThroughCount++
ctx.SendStatus(200)
})
testStatus200(t, app, "/api/v1/user/authenticate", "GET")
utils.AssertEqual(t, 4, runThroughCount, "Loop count")
}

func Test_App_Listen(t *testing.T) {
app := New(&Settings{
DisableStartupMessage: true,
Expand Down
2 changes: 1 addition & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ func (grp *Group) Group(prefix string, handlers ...Handler) *Group {
if len(handlers) > 0 {
grp.app.register("USE", prefix, handlers...)
}
return grp.app.Group(prefix, handlers...)
return grp.app.Group(prefix)
}

0 comments on commit 308ab66

Please sign in to comment.