diff --git a/adaptors/gorillamux/gorillamux_test.go b/adaptors/gorillamux/gorillamux_test.go index 3ad6b999..af9692f9 100644 --- a/adaptors/gorillamux/gorillamux_test.go +++ b/adaptors/gorillamux/gorillamux_test.go @@ -109,6 +109,10 @@ func TestMuxSimple(t *testing.T) { t.Fatalf("Error when comparing length of url parameters %d != %d", len(r.URLParams), len(ctx.URLParams())) } paramsKeyVal := "" + ///TODO: + // Gorilla mux saves and gets its vars by map, so no specific order + // + // I should change this test below: for idxp, p := range r.URLParams { val := ctx.URLParam(p.Key) paramsKeyVal += p.Key + "=" + val + "," diff --git a/context_test.go b/context_test.go index c2d8312a..f8c1881f 100644 --- a/context_test.go +++ b/context_test.go @@ -2,6 +2,7 @@ package iris_test import ( "io/ioutil" + "strconv" "testing" "gopkg.in/kataras/iris.v6" @@ -235,3 +236,35 @@ func TestLimitRequestBodySizeMiddleware(t *testing.T) { e.POST("/").WithBytes(largerBSent).Expect().Status(iris.StatusBadRequest).Body().Equal("http: request body too large") } + +func TestRedirectHTTP(t *testing.T) { + host := "localhost:" + strconv.Itoa(getRandomNumber(1717, 9281)) + + app := iris.New(iris.Configuration{VHost: host}) + app.Adapt(httprouter.New()) + + expectedBody := "Redirected to /redirected" + + app.Get("/redirect", func(ctx *iris.Context) { ctx.Redirect("/redirected") }) + app.Get("/redirected", func(ctx *iris.Context) { ctx.Text(iris.StatusOK, "Redirected to "+ctx.Path()) }) + + e := httptest.New(app, t) + e.GET("/redirect").Expect().Status(iris.StatusOK).Body().Equal(expectedBody) +} + +func TestRedirectHTTPS(t *testing.T) { + + app := iris.New() + app.Adapt(httprouter.New()) + + host := "localhost:" + strconv.Itoa(getRandomNumber(1717, 9281)) + + expectedBody := "Redirected to /redirected" + + app.Get("/redirect", func(ctx *iris.Context) { ctx.Redirect("/redirected") }) + app.Get("/redirected", func(ctx *iris.Context) { ctx.Text(iris.StatusOK, "Redirected to "+ctx.Path()) }) + defer listenTLS(app, host)() + + e := httptest.New(app, t) + e.GET("/redirect").Expect().Status(iris.StatusOK).Body().Equal(expectedBody) +}