Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
4a46dd88
Commit
4a46dd88
authored
Jun 25, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
routing: raise panic if duplicate routes are added
parent
dbfafa1c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
pkg/api/routing/route_register.go
+6
-0
pkg/api/routing/route_register_test.go
+17
-0
No files found.
pkg/api/routing/route_register.go
View file @
4a46dd88
...
@@ -129,6 +129,12 @@ func (rr *routeRegister) route(pattern, method string, handlers ...macaron.Handl
...
@@ -129,6 +129,12 @@ func (rr *routeRegister) route(pattern, method string, handlers ...macaron.Handl
h
=
append
(
h
,
rr
.
subfixHandlers
...
)
h
=
append
(
h
,
rr
.
subfixHandlers
...
)
h
=
append
(
h
,
handlers
...
)
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
{
rr
.
routes
=
append
(
rr
.
routes
,
route
{
method
:
method
,
method
:
method
,
pattern
:
rr
.
prefix
+
pattern
,
pattern
:
rr
.
prefix
+
pattern
,
...
...
pkg/api/routing/route_register_test.go
View file @
4a46dd88
...
@@ -193,6 +193,23 @@ func TestRouteGroupInserting(t *testing.T) {
...
@@ -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
)
{
func
TestNamedMiddlewareRouteRegister
(
t
*
testing
.
T
)
{
testTable
:=
[]
route
{
testTable
:=
[]
route
{
{
method
:
"DELETE"
,
pattern
:
"/admin"
,
handlers
:
emptyHandlers
(
2
)},
{
method
:
"DELETE"
,
pattern
:
"/admin"
,
handlers
:
emptyHandlers
(
2
)},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment