1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

Introduce version 5.0.1

This commit is contained in:
Gerasimos Maropoulos
2016-10-25 15:58:18 +03:00
parent 9958337e5d
commit 78d145c207
8 changed files with 144 additions and 158 deletions

View File

@@ -72,16 +72,24 @@ func TestContextDoNextStop(t *testing.T) {
}
}
type pathParameter struct {
Key string
Value string
}
type pathParameters []pathParameter
// White-box testing *
func TestContextParams(t *testing.T) {
var context iris.Context
params := iris.PathParameters{
iris.PathParameter{Key: "testkey", Value: "testvalue"},
iris.PathParameter{Key: "testkey2", Value: "testvalue2"},
iris.PathParameter{Key: "id", Value: "3"},
iris.PathParameter{Key: "bigint", Value: "548921854390354"},
context := &iris.Context{RequestCtx: &fasthttp.RequestCtx{}}
params := pathParameters{
pathParameter{Key: "testkey", Value: "testvalue"},
pathParameter{Key: "testkey2", Value: "testvalue2"},
pathParameter{Key: "id", Value: "3"},
pathParameter{Key: "bigint", Value: "548921854390354"},
}
for _, p := range params {
context.Set(p.Key, p.Value)
}
context.Params = params
if v := context.Param(params[0].Key); v != params[0].Value {
t.Fatalf("Expecting parameter value to be %s but we got %s", params[0].Value, context.Param("testkey"))
@@ -90,8 +98,8 @@ func TestContextParams(t *testing.T) {
t.Fatalf("Expecting parameter value to be %s but we got %s", params[1].Value, context.Param("testkey2"))
}
if len(context.Params) != len(params) {
t.Fatalf("Expecting to have %d parameters but we got %d", len(params), len(context.Params))
if context.ParamsLen() != len(params) {
t.Fatalf("Expecting to have %d parameters but we got %d", len(params), context.ParamsLen())
}
if vi, err := context.ParamInt(params[2].Key); err != nil {
@@ -111,7 +119,7 @@ func TestContextParams(t *testing.T) {
iris.ResetDefault()
expectedParamsStr := "param1=myparam1,param2=myparam2,param3=myparam3afterstatic,anything=/andhere/anything/you/like"
iris.Get("/path/:param1/:param2/staticpath/:param3/*anything", func(ctx *iris.Context) {
paramsStr := ctx.Params.String()
paramsStr := ctx.ParamsSentence()
ctx.Write(paramsStr)
})
@@ -349,8 +357,8 @@ func TestContextRedirectTo(t *testing.T) {
iris.Get("/mypath", h)("my-path")
iris.Get("/mypostpath", h)("my-post-path")
iris.Get("mypath/with/params/:param1/:param2", func(ctx *iris.Context) {
if len(ctx.Params) != 2 {
t.Fatalf("Strange error, expecting parameters to be two but we got: %d", len(ctx.Params))
if l := ctx.ParamsLen(); l != 2 {
t.Fatalf("Strange error, expecting parameters to be two but we got: %d", l)
}
ctx.Write(ctx.PathString())
})("my-path-with-params")
@@ -462,7 +470,7 @@ func TestContextFlashMessages(t *testing.T) {
firstKey := "name"
lastKey := "package"
values := iris.PathParameters{iris.PathParameter{Key: firstKey, Value: "kataras"}, iris.PathParameter{Key: lastKey, Value: "iris"}}
values := pathParameters{pathParameter{Key: firstKey, Value: "kataras"}, pathParameter{Key: lastKey, Value: "iris"}}
jsonExpected := map[string]string{firstKey: "kataras", lastKey: "iris"}
// set the flashes, the cookies are filled
iris.Put("/set", func(ctx *iris.Context) {