mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
d5b3fef5c9
Signed-off-by: Vishal Rana <vr@labstack.com>
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package echo
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TODO: Fix me
|
|
func TestGroup(t *testing.T) {
|
|
g := New().Group("/group")
|
|
h := func(Context) error { return nil }
|
|
g.CONNECT("/", h)
|
|
g.DELETE("/", h)
|
|
g.GET("/", h)
|
|
g.HEAD("/", h)
|
|
g.OPTIONS("/", h)
|
|
g.PATCH("/", h)
|
|
g.POST("/", h)
|
|
g.PUT("/", h)
|
|
g.TRACE("/", h)
|
|
g.Any("/", h)
|
|
g.Match([]string{GET, POST}, "/", h)
|
|
g.Static("/static", "/tmp")
|
|
g.File("/walle", "_fixture/images//walle.png")
|
|
}
|
|
|
|
func TestGroupRouteMiddleware(t *testing.T) {
|
|
// Ensure middleware slices are not re-used
|
|
e := New()
|
|
g := e.Group("/group")
|
|
h := func(Context) error { return nil }
|
|
m1 := func(next HandlerFunc) HandlerFunc {
|
|
return func(c Context) error {
|
|
return next(c)
|
|
}
|
|
}
|
|
m2 := func(next HandlerFunc) HandlerFunc {
|
|
return func(c Context) error {
|
|
return next(c)
|
|
}
|
|
}
|
|
m3 := func(next HandlerFunc) HandlerFunc {
|
|
return func(c Context) error {
|
|
return next(c)
|
|
}
|
|
}
|
|
m4 := func(next HandlerFunc) HandlerFunc {
|
|
return func(c Context) error {
|
|
return c.NoContent(404)
|
|
}
|
|
}
|
|
m5 := func(next HandlerFunc) HandlerFunc {
|
|
return func(c Context) error {
|
|
return c.NoContent(405)
|
|
}
|
|
}
|
|
g.Use(m1, m2, m3)
|
|
g.GET("/404", h, m4)
|
|
g.GET("/405", h, m5)
|
|
|
|
c, _ := request(GET, "/group/404", e)
|
|
assert.Equal(t, 404, c)
|
|
c, _ = request(GET, "/group/405", e)
|
|
assert.Equal(t, 405, c)
|
|
}
|