MCPcopy
hub / github.com/gofiber/fiber / Test_App_Add_Method_Test

Function Test_App_Add_Method_Test

app_test.go:1052–1078  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1050}
1051
1052func 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
1080func Test_App_All_Method_Test(t *testing.T) {
1081 t.Parallel()

Callers

nothing calls this directly

Calls 3

TestMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65

Tested by

no test coverage detected