mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
routing: raise panic if duplicate routes are added
This commit is contained in:
parent
dbfafa1cb5
commit
4a46dd886b
@ -129,6 +129,12 @@ func (rr *routeRegister) route(pattern, method string, handlers ...macaron.Handl
|
||||
h = append(h, rr.subfixHandlers...)
|
||||
h = append(h, handlers...)
|
||||
|
||||
for _, r := range rr.routes {
|
||||
if r.pattern == rr.prefix+pattern && r.method == method {
|
||||
panic("cannot add duplicate route")
|
||||
}
|
||||
}
|
||||
|
||||
rr.routes = append(rr.routes, route{
|
||||
method: method,
|
||||
pattern: rr.prefix + pattern,
|
||||
|
@ -193,6 +193,23 @@ func TestRouteGroupInserting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuplicateRoutShouldPanic(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() != "cannot add duplicate route" {
|
||||
t.Errorf("Should cause panic if duplicate routes are added ")
|
||||
}
|
||||
}()
|
||||
|
||||
rr := NewRouteRegister(func(name string) macaron.Handler {
|
||||
return emptyHandler(name)
|
||||
})
|
||||
|
||||
rr.Get("/api", emptyHandler("1"))
|
||||
rr.Get("/api", emptyHandler("1"))
|
||||
|
||||
fr := &fakeRouter{}
|
||||
rr.Register(fr)
|
||||
}
|
||||
func TestNamedMiddlewareRouteRegister(t *testing.T) {
|
||||
testTable := []route{
|
||||
{method: "DELETE", pattern: "/admin", handlers: emptyHandlers(2)},
|
||||
|
Loading…
Reference in New Issue
Block a user