| 407 | } |
| 408 | |
| 409 | func TestGroup_MatchWithErrors(t *testing.T) { |
| 410 | e := New() |
| 411 | |
| 412 | users := e.Group("/users") |
| 413 | users.GET("/activate", func(c *Context) error { |
| 414 | return c.String(http.StatusOK, "OK") |
| 415 | }) |
| 416 | myMethods := []string{http.MethodGet, http.MethodPost} |
| 417 | |
| 418 | errs := func() (errs []error) { |
| 419 | defer func() { |
| 420 | if r := recover(); r != nil { |
| 421 | if tmpErr, ok := r.([]error); ok { |
| 422 | errs = tmpErr |
| 423 | return |
| 424 | } |
| 425 | panic(r) |
| 426 | } |
| 427 | }() |
| 428 | |
| 429 | users.Match(myMethods, "/activate", func(c *Context) error { |
| 430 | return c.String(http.StatusTeapot, "OK") |
| 431 | }) |
| 432 | return nil |
| 433 | }() |
| 434 | assert.Len(t, errs, 1) |
| 435 | assert.EqualError(t, errs[0], "GET /users/activate: adding duplicate route (same method+path) is not allowed") |
| 436 | |
| 437 | for _, m := range myMethods { |
| 438 | status, body := request(m, "/users/activate", e) |
| 439 | |
| 440 | expect := http.StatusTeapot |
| 441 | if m == http.MethodGet { |
| 442 | expect = http.StatusOK |
| 443 | } |
| 444 | assert.Equal(t, expect, status) |
| 445 | assert.Equal(t, `OK`, body) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | func TestGroup_Static(t *testing.T) { |
| 450 | e := New() |