2019-06-21 18:43:25 +02:00
|
|
|
// white-box testing
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-08-17 09:06:20 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/macro"
|
2019-06-21 18:43:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRouteStaticPath(t *testing.T) {
|
2019-08-17 09:06:20 +02:00
|
|
|
tests := []struct {
|
2019-06-21 18:43:25 +02:00
|
|
|
tmpl string
|
|
|
|
static string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
tmpl: "/files/{file:path}",
|
|
|
|
static: "/files",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/path",
|
|
|
|
static: "/path",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/path/segment",
|
|
|
|
static: "/path/segment",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/path/segment/{n:int}",
|
|
|
|
static: "/path/segment",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/path/{n:uint64}/{n:int}",
|
|
|
|
static: "/path",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/path/{n:uint64}/static",
|
|
|
|
static: "/path",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/{name}",
|
|
|
|
static: "/",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tmpl: "/",
|
|
|
|
static: "/",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
route := Route{tmpl: macro.Template{Src: tt.tmpl}}
|
|
|
|
if expected, got := tt.static, route.StaticPath(); expected != got {
|
|
|
|
t.Fatalf("[%d:%s] expected static path to be: '%s' but got: '%s'", i, tt.tmpl, expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|