MCPcopy
hub / github.com/labstack/echo / TestEchoGroup

Function TestEchoGroup

echo_test.go:997–1053  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

995}
996
997func TestEchoGroup(t *testing.T) {
998 e := New()
999 buf := new(bytes.Buffer)
1000 e.Use(MiddlewareFunc(func(next HandlerFunc) HandlerFunc {
1001 return func(c *Context) error {
1002 buf.WriteString("0")
1003 return next(c)
1004 }
1005 }))
1006 h := func(c *Context) error {
1007 return c.NoContent(http.StatusOK)
1008 }
1009
1010 //--------
1011 // Routes
1012 //--------
1013
1014 e.GET("/users", h)
1015
1016 // Group
1017 g1 := e.Group("/group1")
1018 g1.Use(func(next HandlerFunc) HandlerFunc {
1019 return func(c *Context) error {
1020 buf.WriteString("1")
1021 return next(c)
1022 }
1023 })
1024 g1.GET("", h)
1025
1026 // Nested groups with middleware
1027 g2 := e.Group("/group2")
1028 g2.Use(func(next HandlerFunc) HandlerFunc {
1029 return func(c *Context) error {
1030 buf.WriteString("2")
1031 return next(c)
1032 }
1033 })
1034 g3 := g2.Group("/group3")
1035 g3.Use(func(next HandlerFunc) HandlerFunc {
1036 return func(c *Context) error {
1037 buf.WriteString("3")
1038 return next(c)
1039 }
1040 })
1041 g3.GET("", h)
1042
1043 request(http.MethodGet, "/users", e)
1044 assert.Equal(t, "0", buf.String())
1045
1046 buf.Reset()
1047 request(http.MethodGet, "/group1", e)
1048 assert.Equal(t, "01", buf.String())
1049
1050 buf.Reset()
1051 request(http.MethodGet, "/group2/group3", e)
1052 assert.Equal(t, "023", buf.String())
1053}
1054

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
MiddlewareFuncFuncType · 0.85
requestFunction · 0.85
NoContentMethod · 0.80
UseMethod · 0.45
GETMethod · 0.45
GroupMethod · 0.45
StringMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…