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

Function Test_Domain_HTTPMethods

domain_test.go:246–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

244}
245
246func Test_Domain_HTTPMethods(t *testing.T) {
247 t.Parallel()
248
249 methods := []struct {
250 reg func(Router, string, any, ...any) Router
251 method string
252 }{
253 {method: MethodGet, reg: func(r Router, p string, h any, hs ...any) Router { return r.Get(p, h, hs...) }},
254 {method: MethodPost, reg: func(r Router, p string, h any, hs ...any) Router { return r.Post(p, h, hs...) }},
255 {method: MethodPut, reg: func(r Router, p string, h any, hs ...any) Router { return r.Put(p, h, hs...) }},
256 {method: MethodDelete, reg: func(r Router, p string, h any, hs ...any) Router { return r.Delete(p, h, hs...) }},
257 {method: MethodPatch, reg: func(r Router, p string, h any, hs ...any) Router { return r.Patch(p, h, hs...) }},
258 {method: MethodQuery, reg: func(r Router, p string, h any, hs ...any) Router { return r.Query(p, h, hs...) }},
259 {method: MethodOptions, reg: func(r Router, p string, h any, hs ...any) Router { return r.Options(p, h, hs...) }},
260 {method: MethodConnect, reg: func(r Router, p string, h any, hs ...any) Router { return r.Connect(p, h, hs...) }},
261 {method: MethodTrace, reg: func(r Router, p string, h any, hs ...any) Router { return r.Trace(p, h, hs...) }},
262 }
263
264 for _, m := range methods {
265 t.Run(m.method, func(t *testing.T) {
266 t.Parallel()
267 app := New()
268
269 domain := app.Domain("api.example.com")
270 m.reg(domain, "/test", func(c Ctx) error {
271 return c.SendString(m.method)
272 })
273
274 req := httptest.NewRequest(m.method, "/test", http.NoBody)
275 req.Host = "api.example.com"
276 resp, err := app.Test(req)
277 require.NoError(t, err)
278 require.Equal(t, StatusOK, resp.StatusCode)
279 })
280 }
281}
282
283func Test_Domain_Head(t *testing.T) {
284 t.Parallel()

Callers

nothing calls this directly

Calls 13

TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
PostMethod · 0.65
PutMethod · 0.65
DeleteMethod · 0.65
PatchMethod · 0.65
QueryMethod · 0.65
OptionsMethod · 0.65
ConnectMethod · 0.65
TraceMethod · 0.65
DomainMethod · 0.65

Tested by

no test coverage detected