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

Function TestRouter_RouteWhenNotFoundRouteWithNodeSplitting

router_test.go:3331–3364  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3329}
3330
3331func TestRouter_RouteWhenNotFoundRouteWithNodeSplitting(t *testing.T) {
3332 e := New()
3333 r := e.router
3334
3335 hf := func(c *Context) error {
3336 return c.String(http.StatusOK, c.RouteInfo().Name)
3337 }
3338 r.Add(Route{Method: http.MethodGet, Path: "/test*", Handler: hf, Name: "0"})
3339 r.Add(Route{Method: RouteNotFound, Path: "/test*", Handler: hf, Name: "1"})
3340 r.Add(Route{Method: RouteNotFound, Path: "/test", Handler: hf, Name: "2"})
3341
3342 // Tree before:
3343 // 1 `/`
3344 // 1.1 `*` (any) ID=1
3345 // 1.2 `test` (static) ID=2
3346 // 1.2.1 `*` (any) ID=0
3347
3348 // node with path `test` has routeNotFound handler from previous Add call. Now when we insert `/te/st*` into router tree
3349 // This means that node `test` is split into `te` and `st` nodes and new node `/st*` is inserted.
3350 // On that split `/test` routeNotFound handler must not be lost.
3351 r.Add(Route{Method: http.MethodGet, Path: "/te/st*", Handler: hf, Name: "3"})
3352 // Tree after:
3353 // 1 `/`
3354 // 1.1 `*` (any) ID=1
3355 // 1.2 `te` (static)
3356 // 1.2.1 `st` (static) ID=2
3357 // 1.2.1.1 `*` (any) ID=0
3358 // 1.2.2 `/st` (static)
3359 // 1.2.2.1 `*` (any) ID=3
3360
3361 _, body := request(http.MethodPut, "/test", e)
3362
3363 assert.Equal(t, "2", body)
3364}
3365
3366func TestRouter_RouteWhenNotFoundRouteAnyKind(t *testing.T) {
3367 var testCases = []struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
requestFunction · 0.85
RouteInfoMethod · 0.80
AddMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…