MCPcopy
hub / github.com/gorilla/mux / TestPathPrefix

Function TestPathPrefix

mux_test.go:465–543  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

463}
464
465func TestPathPrefix(t *testing.T) {
466 tests := []routeTest{
467 {
468 title: "PathPrefix route, match",
469 route: new(Route).PathPrefix("/111"),
470 request: newRequest("GET", "http://localhost/111/222/333"),
471 vars: map[string]string{},
472 host: "",
473 path: "/111",
474 shouldMatch: true,
475 },
476 {
477 title: "PathPrefix route, match substring",
478 route: new(Route).PathPrefix("/1"),
479 request: newRequest("GET", "http://localhost/111/222/333"),
480 vars: map[string]string{},
481 host: "",
482 path: "/1",
483 shouldMatch: true,
484 },
485 {
486 title: "PathPrefix route, URL prefix in request does not match",
487 route: new(Route).PathPrefix("/111"),
488 request: newRequest("GET", "http://localhost/1/2/3"),
489 vars: map[string]string{},
490 host: "",
491 path: "/111",
492 shouldMatch: false,
493 },
494 {
495 title: "PathPrefix route with pattern, match",
496 route: new(Route).PathPrefix("/111/{v1:[0-9]{3}}"),
497 request: newRequest("GET", "http://localhost/111/222/333"),
498 vars: map[string]string{"v1": "222"},
499 host: "",
500 path: "/111/222",
501 pathTemplate: `/111/{v1:[0-9]{3}}`,
502 shouldMatch: true,
503 },
504 {
505 title: "PathPrefix route with pattern, URL prefix in request does not match",
506 route: new(Route).PathPrefix("/111/{v1:[0-9]{3}}"),
507 request: newRequest("GET", "http://localhost/111/aaa/333"),
508 vars: map[string]string{"v1": "222"},
509 host: "",
510 path: "/111/222",
511 pathTemplate: `/111/{v1:[0-9]{3}}`,
512 shouldMatch: false,
513 },
514 {
515 title: "PathPrefix route with multiple patterns, match",
516 route: new(Route).PathPrefix("/{v1:[0-9]{3}}/{v2:[0-9]{3}}"),
517 request: newRequest("GET", "http://localhost/111/222/333"),
518 vars: map[string]string{"v1": "111", "v2": "222"},
519 host: "",
520 path: "/111/222",
521 pathTemplate: `/{v1:[0-9]{3}}/{v2:[0-9]{3}}`,
522 shouldMatch: true,

Callers

nothing calls this directly

Calls 5

newRequestFunction · 0.85
testRouteFunction · 0.85
testTemplateFunction · 0.85
testUseEscapedRouteFunction · 0.85
PathPrefixMethod · 0.45

Tested by

no test coverage detected