MCPcopy
hub / github.com/labstack/echo / TestEchoMiddleware

Function TestEchoMiddleware

echo_test.go:639–682  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

637}
638
639func TestEchoMiddleware(t *testing.T) {
640 e := New()
641 buf := new(bytes.Buffer)
642
643 e.Pre(func(next HandlerFunc) HandlerFunc {
644 return func(c *Context) error {
645 // before route match is found RouteInfo does not exist
646 assert.Equal(t, RouteInfo{}, c.RouteInfo())
647 buf.WriteString("-1")
648 return next(c)
649 }
650 })
651
652 e.Use(func(next HandlerFunc) HandlerFunc {
653 return func(c *Context) error {
654 buf.WriteString("1")
655 return next(c)
656 }
657 })
658
659 e.Use(func(next HandlerFunc) HandlerFunc {
660 return func(c *Context) error {
661 buf.WriteString("2")
662 return next(c)
663 }
664 })
665
666 e.Use(func(next HandlerFunc) HandlerFunc {
667 return func(c *Context) error {
668 buf.WriteString("3")
669 return next(c)
670 }
671 })
672
673 // Route
674 e.GET("/", func(c *Context) error {
675 return c.String(http.StatusOK, "OK")
676 })
677
678 c, b := request(http.MethodGet, "/", e)
679 assert.Equal(t, "-1123", buf.String())
680 assert.Equal(t, http.StatusOK, c)
681 assert.Equal(t, "OK", b)
682}
683
684func TestEchoMiddlewareError(t *testing.T) {
685 e := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
requestFunction · 0.85
PreMethod · 0.80
RouteInfoMethod · 0.80
UseMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…