2017-12-25 19:05:32 +01:00
|
|
|
package hero
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/context"
|
2017-12-25 19:05:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathParams(t *testing.T) {
|
|
|
|
got := ""
|
|
|
|
h := New()
|
|
|
|
handler := h.Handler(func(firstname string, lastname string) {
|
|
|
|
got = firstname + lastname
|
|
|
|
})
|
|
|
|
|
|
|
|
h.Register(func(ctx context.Context) func() string { return func() string { return "" } })
|
|
|
|
handlerWithOther := h.Handler(func(f func() string, firstname string, lastname string) {
|
|
|
|
got = f() + firstname + lastname
|
|
|
|
})
|
|
|
|
|
|
|
|
handlerWithOtherBetweenThem := h.Handler(func(firstname string, f func() string, lastname string) {
|
2020-02-29 13:18:15 +01:00
|
|
|
got = firstname + lastname
|
2017-12-25 19:05:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx := context.NewContext(nil)
|
|
|
|
ctx.Params().Set("firstname", "Gerasimos")
|
|
|
|
ctx.Params().Set("lastname", "Maropoulos")
|
|
|
|
handler(ctx)
|
|
|
|
expected := "GerasimosMaropoulos"
|
|
|
|
if got != expected {
|
2020-02-29 13:18:15 +01:00
|
|
|
t.Fatalf("[0] expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
2017-12-25 19:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
got = ""
|
|
|
|
handlerWithOther(ctx)
|
|
|
|
expected = "GerasimosMaropoulos"
|
|
|
|
if got != expected {
|
2020-02-29 13:18:15 +01:00
|
|
|
t.Fatalf("[1] expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
2017-12-25 19:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
got = ""
|
|
|
|
handlerWithOtherBetweenThem(ctx)
|
|
|
|
expected = "GerasimosMaropoulos"
|
|
|
|
if got != expected {
|
2020-02-29 13:18:15 +01:00
|
|
|
t.Fatalf("[2] expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
2017-12-25 19:05:32 +01:00
|
|
|
}
|
|
|
|
}
|