mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
Add fallback handlers
Former-commit-id: f7e9bd17076a10e1ed1702780d7ce9e89f00b592
This commit is contained in:
41
core/router/router_test.go
Normal file
41
core/router/router_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package router_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
func TestRouteExists(t *testing.T) {
|
||||
// build the api
|
||||
app := iris.New()
|
||||
emptyHandler := func(context.Context) {}
|
||||
|
||||
// setup the tested routes
|
||||
app.Handle("GET", "/route-exists", emptyHandler)
|
||||
app.Handle("POST", "/route-with-param/{param}", emptyHandler)
|
||||
|
||||
// check RouteExists
|
||||
app.Handle("GET", "/route-test", func(ctx context.Context) {
|
||||
if ctx.RouteExists("GET", "/route-not-exists") {
|
||||
t.Error("Route with path should not exists")
|
||||
}
|
||||
|
||||
if ctx.RouteExists("POST", "/route-exists") {
|
||||
t.Error("Route with method should not exists")
|
||||
}
|
||||
|
||||
if !ctx.RouteExists("GET", "/route-exists") {
|
||||
t.Error("Route 1 should exists")
|
||||
}
|
||||
|
||||
if !ctx.RouteExists("POST", "/route-with-param/a-param") {
|
||||
t.Error("Route 2 should exists")
|
||||
}
|
||||
})
|
||||
|
||||
// run the tests
|
||||
httptest.New(t, app, httptest.Debug(false)).Request("GET", "/route-test").Expect().Status(iris.StatusOK)
|
||||
}
|
||||
Reference in New Issue
Block a user