Add a TestRedirectHTTP/HTTPS

Former-commit-id: 0739e0cb4dc15c317b66b8da812cbd83fa0ea32f
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-02-19 09:45:05 +02:00
parent 1d60df1237
commit f9b2b8aa69
2 changed files with 37 additions and 0 deletions

View File

@ -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 + ","

View File

@ -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)
}