| 244 | } |
| 245 | |
| 246 | func 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 | |
| 283 | func Test_Domain_Head(t *testing.T) { |
| 284 | t.Parallel() |