(t *testing.T)
| 703 | } |
| 704 | |
| 705 | func TestRouterParam(t *testing.T) { |
| 706 | e := New() |
| 707 | |
| 708 | e.GET("/users/:id", handlerFunc) |
| 709 | |
| 710 | var testCases = []struct { |
| 711 | expectRoute any |
| 712 | expectParam map[string]string |
| 713 | name string |
| 714 | whenURL string |
| 715 | }{ |
| 716 | { |
| 717 | name: "route /users/1 to /users/:id", |
| 718 | whenURL: "/users/1", |
| 719 | expectRoute: "/users/:id", |
| 720 | expectParam: map[string]string{"id": "1"}, |
| 721 | }, |
| 722 | { |
| 723 | name: "route /users/1/ to /users/:id", |
| 724 | whenURL: "/users/1/", |
| 725 | expectRoute: "/users/:id", |
| 726 | expectParam: map[string]string{"id": "1/"}, |
| 727 | }, |
| 728 | } |
| 729 | |
| 730 | for _, tc := range testCases { |
| 731 | t.Run(tc.name, func(t *testing.T) { |
| 732 | c := e.NewContext(nil, nil) |
| 733 | c.SetRequest(httptest.NewRequest(http.MethodGet, tc.whenURL, nil)) |
| 734 | _ = e.router.Route(c) |
| 735 | |
| 736 | assert.Equal(t, tc.expectRoute, c.Path()) |
| 737 | for param, expectedValue := range tc.expectParam { |
| 738 | assert.Equal(t, expectedValue, c.pathValues.GetOr(param, "---none---")) |
| 739 | } |
| 740 | checkUnusedParamValues(t, c, tc.expectParam) |
| 741 | }) |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | func TestRouter_addAndMatchAllSupportedMethods(t *testing.T) { |
| 746 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…