mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
3945fa68d1
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c. Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package hero
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kataras/iris/v12/context"
|
|
)
|
|
|
|
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) {
|
|
got = f() + firstname + lastname
|
|
})
|
|
|
|
ctx := context.NewContext(nil)
|
|
ctx.Params().Set("firstname", "Gerasimos")
|
|
ctx.Params().Set("lastname", "Maropoulos")
|
|
handler(ctx)
|
|
expected := "GerasimosMaropoulos"
|
|
if got != expected {
|
|
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
|
}
|
|
|
|
got = ""
|
|
handlerWithOther(ctx)
|
|
expected = "GerasimosMaropoulos"
|
|
if got != expected {
|
|
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
|
}
|
|
|
|
got = ""
|
|
handlerWithOtherBetweenThem(ctx)
|
|
expected = "GerasimosMaropoulos"
|
|
if got != expected {
|
|
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
|
|
}
|
|
}
|