MCPcopy Index your code
hub / github.com/labstack/echo / TestGroup_RouteNotFoundWithMiddleware

Function TestGroup_RouteNotFoundWithMiddleware

group_test.go:742–814  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

740}
741
742func TestGroup_RouteNotFoundWithMiddleware(t *testing.T) {
743 var testCases = []struct {
744 expectBody any
745 name string
746 whenURL string
747 expectCode int
748 givenCustom404 bool
749 expectMiddlewareCalled bool
750 }{
751 {
752 name: "ok, custom 404 handler is called with middleware",
753 givenCustom404: true,
754 whenURL: "/group/test3",
755 expectBody: "404 GET /group/*",
756 expectCode: http.StatusNotFound,
757 expectMiddlewareCalled: true, // because RouteNotFound is added after middleware is added
758 },
759 {
760 name: "ok, default group 404 handler is not called with middleware",
761 givenCustom404: false,
762 whenURL: "/group/test3",
763 expectBody: "404 GET /*",
764 expectCode: http.StatusNotFound,
765 expectMiddlewareCalled: false, // because RouteNotFound is added before middleware is added
766 },
767 {
768 name: "ok, (no slash) default group 404 handler is called with middleware",
769 givenCustom404: false,
770 whenURL: "/group",
771 expectBody: "404 GET /*",
772 expectCode: http.StatusNotFound,
773 expectMiddlewareCalled: false, // because RouteNotFound is added before middleware is added
774 },
775 }
776 for _, tc := range testCases {
777 t.Run(tc.name, func(t *testing.T) {
778
779 okHandler := func(c *Context) error {
780 return c.String(http.StatusOK, c.Request().Method+" "+c.Path())
781 }
782 notFoundHandler := func(c *Context) error {
783 return c.String(http.StatusNotFound, "404 "+c.Request().Method+" "+c.Path())
784 }
785
786 e := New()
787 e.GET("/test1", okHandler)
788 e.RouteNotFound("/*", notFoundHandler)
789
790 g := e.Group("/group")
791 g.GET("/test1", okHandler)
792
793 middlewareCalled := false
794 g.Use(func(next HandlerFunc) HandlerFunc {
795 return func(c *Context) error {
796 middlewareCalled = true
797 return next(c)
798 }
799 })

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
RequestMethod · 0.80
PathMethod · 0.80
ServeHTTPMethod · 0.80
StringMethod · 0.45
GETMethod · 0.45
RouteNotFoundMethod · 0.45
GroupMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…