mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Add a TestRedirectHTTP/HTTPS
Former-commit-id: 0739e0cb4dc15c317b66b8da812cbd83fa0ea32f
This commit is contained in:
parent
1d60df1237
commit
f9b2b8aa69
|
@ -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 + ","
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user