From 7a1126fb16449f3142e918ff546a2d611c48f4e3 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 10 Nov 2020 19:50:32 +0200 Subject: [PATCH] Add a test --- group_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/group_test.go b/group_test.go index c51fd91e..d4a6846f 100644 --- a/group_test.go +++ b/group_test.go @@ -119,3 +119,37 @@ 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) +}