| 917 | } |
| 918 | |
| 919 | func Test_App_Not_Use_StrictRouting(t *testing.T) { |
| 920 | t.Parallel() |
| 921 | app := New() |
| 922 | |
| 923 | app.Use("/abc", func(c Ctx) error { |
| 924 | return c.SendString(c.Path()) |
| 925 | }) |
| 926 | |
| 927 | g := app.Group("/foo") |
| 928 | g.Use("/", func(c Ctx) error { |
| 929 | return c.SendString(c.Path()) |
| 930 | }) |
| 931 | |
| 932 | // wrong path in the requested route -> 404 |
| 933 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/abc/", http.NoBody)) |
| 934 | require.NoError(t, err, "app.Test(req)") |
| 935 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 936 | |
| 937 | // right path in the requested route -> 200 |
| 938 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/abc", http.NoBody)) |
| 939 | require.NoError(t, err, "app.Test(req)") |
| 940 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 941 | |
| 942 | // wrong path with group in the requested route -> 404 |
| 943 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo", http.NoBody)) |
| 944 | require.NoError(t, err, "app.Test(req)") |
| 945 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 946 | |
| 947 | // right path with group in the requested route -> 200 |
| 948 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/", http.NoBody)) |
| 949 | require.NoError(t, err, "app.Test(req)") |
| 950 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 951 | } |
| 952 | |
| 953 | func Test_App_Use_MultiplePrefix(t *testing.T) { |
| 954 | t.Parallel() |