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

Function TestEcho_RouteNotFound

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

Source from the content-addressed store, hash-verified

1053}
1054
1055func TestEcho_RouteNotFound(t *testing.T) {
1056 var testCases = []struct {
1057 expectRoute any
1058 name string
1059 whenURL string
1060 expectCode int
1061 }{
1062 {
1063 name: "404, route to static not found handler /a/c/xx",
1064 whenURL: "/a/c/xx",
1065 expectRoute: "GET /a/c/xx",
1066 expectCode: http.StatusNotFound,
1067 },
1068 {
1069 name: "404, route to path param not found handler /a/:file",
1070 whenURL: "/a/echo.exe",
1071 expectRoute: "GET /a/:file",
1072 expectCode: http.StatusNotFound,
1073 },
1074 {
1075 name: "404, route to any not found handler /*",
1076 whenURL: "/b/echo.exe",
1077 expectRoute: "GET /*",
1078 expectCode: http.StatusNotFound,
1079 },
1080 {
1081 name: "200, route /a/c/df to /a/c/df",
1082 whenURL: "/a/c/df",
1083 expectRoute: "GET /a/c/df",
1084 expectCode: http.StatusOK,
1085 },
1086 }
1087
1088 for _, tc := range testCases {
1089 t.Run(tc.name, func(t *testing.T) {
1090 e := New()
1091
1092 okHandler := func(c *Context) error {
1093 return c.String(http.StatusOK, c.Request().Method+" "+c.Path())
1094 }
1095 notFoundHandler := func(c *Context) error {
1096 return c.String(http.StatusNotFound, c.Request().Method+" "+c.Path())
1097 }
1098
1099 e.GET("/", okHandler)
1100 e.GET("/a/c/df", okHandler)
1101 e.GET("/a/b*", okHandler)
1102 e.PUT("/*", okHandler)
1103
1104 e.RouteNotFound("/a/c/xx", notFoundHandler) // static
1105 e.RouteNotFound("/a/:file", notFoundHandler) // param
1106 e.RouteNotFound("/*", notFoundHandler) // any
1107
1108 req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil)
1109 rec := httptest.NewRecorder()
1110
1111 e.ServeHTTP(rec, req)
1112

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
RequestMethod · 0.80
PathMethod · 0.80
ServeHTTPMethod · 0.80
StringMethod · 0.45
GETMethod · 0.45
PUTMethod · 0.45
RouteNotFoundMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…