| 1016 | } |
| 1017 | |
| 1018 | func Test_App_Use_StrictRouting(t *testing.T) { |
| 1019 | t.Parallel() |
| 1020 | app := New(Config{StrictRouting: true}) |
| 1021 | |
| 1022 | app.Get("/abc", func(c Ctx) error { |
| 1023 | return c.SendString(c.Path()) |
| 1024 | }) |
| 1025 | |
| 1026 | g := app.Group("/foo") |
| 1027 | g.Get("/", func(c Ctx) error { |
| 1028 | return c.SendString(c.Path()) |
| 1029 | }) |
| 1030 | |
| 1031 | // wrong path in the requested route -> 404 |
| 1032 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/abc/", http.NoBody)) |
| 1033 | require.NoError(t, err, "app.Test(req)") |
| 1034 | require.Equal(t, StatusNotFound, resp.StatusCode, "Status code") |
| 1035 | |
| 1036 | // right path in the requested route -> 200 |
| 1037 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/abc", http.NoBody)) |
| 1038 | require.NoError(t, err, "app.Test(req)") |
| 1039 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 1040 | |
| 1041 | // wrong path with group in the requested route -> 404 |
| 1042 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo", http.NoBody)) |
| 1043 | require.NoError(t, err, "app.Test(req)") |
| 1044 | require.Equal(t, StatusNotFound, resp.StatusCode, "Status code") |
| 1045 | |
| 1046 | // right path with group in the requested route -> 200 |
| 1047 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/", http.NoBody)) |
| 1048 | require.NoError(t, err, "app.Test(req)") |
| 1049 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 1050 | } |
| 1051 | |
| 1052 | func Test_App_Add_Method_Test(t *testing.T) { |
| 1053 | t.Parallel() |