| 
									
										
										
										
											2015-05-29 16:00:02 -07:00
										 |  |  | package echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-10-14 17:16:58 +02:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04:00
										 |  |  | 	"testing" | 
					
						
							| 
									
										
										
										
											2016-09-23 05:31:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/assert" | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-05-29 16:00:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-06 16:54:24 -07:00
										 |  |  | // TODO: Fix me | 
					
						
							| 
									
										
										
										
											2015-05-30 15:20:36 -07:00
										 |  |  | func TestGroup(t *testing.T) { | 
					
						
							|  |  |  | 	g := New().Group("/group") | 
					
						
							| 
									
										
										
										
											2016-04-02 14:19:39 -07:00
										 |  |  | 	h := func(Context) error { return nil } | 
					
						
							| 
									
										
										
										
											2016-04-20 07:32:51 -07:00
										 |  |  | 	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) | 
					
						
							| 
									
										
										
										
											2016-04-09 14:00:23 -07:00
										 |  |  | 	g.Any("/", h) | 
					
						
							| 
									
										
										
										
											2018-10-14 17:16:58 +02:00
										 |  |  | 	g.Match([]string{http.MethodGet, http.MethodPost}, "/", h) | 
					
						
							| 
									
										
										
										
											2016-04-09 14:00:23 -07:00
										 |  |  | 	g.Static("/static", "/tmp") | 
					
						
							|  |  |  | 	g.File("/walle", "_fixture/images//walle.png") | 
					
						
							| 
									
										
										
										
											2015-05-29 16:00:02 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04: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 05:31:48 -07: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-13 21:50:17 -04:00
										 |  |  | 	g.Use(m1, m2, m3) | 
					
						
							|  |  |  | 	g.GET("/404", h, m4) | 
					
						
							|  |  |  | 	g.GET("/405", h, m5) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-14 17:16:58 +02:00
										 |  |  | 	c, _ := request(http.MethodGet, "/group/404", e) | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04:00
										 |  |  | 	assert.Equal(t, 404, c) | 
					
						
							| 
									
										
										
										
											2018-10-14 17:16:58 +02:00
										 |  |  | 	c, _ = request(http.MethodGet, "/group/405", e) | 
					
						
							| 
									
										
										
										
											2016-06-13 21:50:17 -04:00
										 |  |  | 	assert.Equal(t, 405, c) | 
					
						
							|  |  |  | } |