| 1050 | } |
| 1051 | |
| 1052 | func Test_App_Add_Method_Test(t *testing.T) { |
| 1053 | t.Parallel() |
| 1054 | |
| 1055 | methods := append(DefaultMethods, "JOHN") //nolint:gocritic // We want a new slice here |
| 1056 | app := New(Config{ |
| 1057 | RequestMethods: methods, |
| 1058 | }) |
| 1059 | |
| 1060 | app.Add([]string{"JOHN"}, "/john", testEmptyHandler) |
| 1061 | |
| 1062 | resp, err := app.Test(httptest.NewRequest("JOHN", "/john", http.NoBody)) |
| 1063 | require.NoError(t, err, "app.Test(req)") |
| 1064 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 1065 | |
| 1066 | resp, err = app.Test(httptest.NewRequest(MethodGet, "/john", http.NoBody)) |
| 1067 | require.NoError(t, err, "app.Test(req)") |
| 1068 | require.Equal(t, StatusMethodNotAllowed, resp.StatusCode, "Status code") |
| 1069 | |
| 1070 | resp, err = app.Test(httptest.NewRequest("UNKNOWN", "/john", http.NoBody)) |
| 1071 | require.NoError(t, err, "app.Test(req)") |
| 1072 | require.Equal(t, StatusNotImplemented, resp.StatusCode, "Status code") |
| 1073 | |
| 1074 | // Add a new method |
| 1075 | require.Panics(t, func() { |
| 1076 | app.Add([]string{"JANE"}, "/jane", testEmptyHandler) |
| 1077 | }) |
| 1078 | } |
| 1079 | |
| 1080 | func Test_App_All_Method_Test(t *testing.T) { |
| 1081 | t.Parallel() |