MCPcopy Index your code
hub / github.com/labstack/echo / TestGroup_MatchWithErrors

Function TestGroup_MatchWithErrors

group_test.go:409–447  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

407}
408
409func 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
449func TestGroup_Static(t *testing.T) {
450 e := New()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
requestFunction · 0.85
GroupMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45
MatchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…