iris/core/router/router_test.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

42 lines
1.0 KiB
Go

package router_test
import (
"testing"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/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)
}