2015-05-30 01:00:02 +02:00
|
|
|
package echo
|
|
|
|
|
2016-06-14 03:50:17 +02:00
|
|
|
import (
|
|
|
|
"testing"
|
2016-09-23 14:31:48 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-06-14 03:50:17 +02:00
|
|
|
)
|
2015-05-30 01:00:02 +02:00
|
|
|
|
2016-06-07 01:54:24 +02:00
|
|
|
// TODO: Fix me
|
2015-05-31 00:20:36 +02:00
|
|
|
func TestGroup(t *testing.T) {
|
|
|
|
g := New().Group("/group")
|
2016-04-02 23:19:39 +02:00
|
|
|
h := func(Context) error { return nil }
|
2016-04-20 16:32:51 +02:00
|
|
|
g.CONNECT("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Connect("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.DELETE("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Delete("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.GET("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Get("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.HEAD("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Head("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.OPTIONS("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Options("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.PATCH("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Patch("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.POST("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Post("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.PUT("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Put("/", h)
|
2016-04-20 16:32:51 +02:00
|
|
|
g.TRACE("/", h)
|
2016-06-07 01:54:24 +02:00
|
|
|
g.Trace("/", h)
|
2016-04-09 23:00:23 +02:00
|
|
|
g.Any("/", h)
|
|
|
|
g.Match([]string{GET, POST}, "/", h)
|
|
|
|
g.Static("/static", "/tmp")
|
|
|
|
g.File("/walle", "_fixture/images//walle.png")
|
2015-05-30 01:00:02 +02:00
|
|
|
}
|
2016-06-14 03:50:17 +02:00
|
|
|
|
|
|
|
func TestGroupRouteMiddleware(t *testing.T) {
|
|
|
|
// Ensure middleware slices are not re-used
|
|
|
|
e := New()
|
|
|
|
g := e.Group("/group")
|
|
|
|
h := func(Context) error { return nil }
|
2016-09-23 14:31:48 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 03:50:17 +02:00
|
|
|
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)
|
|
|
|
}
|