mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 21:15:56 +00:00
Read https://github.com/kataras/iris/tree/master/HISTORY.md
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/gavv/httpexpect"
|
||||
"github.com/gavv/httpexpect/fasthttpexpect"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/config"
|
||||
)
|
||||
|
||||
var notFoundMessage = "Iris custom message for 404 not found"
|
||||
@@ -46,15 +45,7 @@ func TestCustomErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
api.PreListen(config.Server{ListeningAddr: ""})
|
||||
|
||||
// create httpexpect instance that will call fasthtpp.RequestHandler directly
|
||||
e := httpexpect.WithConfig(httpexpect.Config{
|
||||
Reporter: httpexpect.NewAssertReporter(t),
|
||||
Client: fasthttpexpect.NewBinder(api.ServeRequest),
|
||||
})
|
||||
// first register the custom errors
|
||||
|
||||
// register the custom errors
|
||||
api.OnError(404, func(ctx *iris.Context) {
|
||||
ctx.Write("%s", notFoundMessage)
|
||||
})
|
||||
@@ -63,6 +54,12 @@ func TestCustomErrors(t *testing.T) {
|
||||
ctx.Write("%s", internalServerMessage)
|
||||
})
|
||||
|
||||
// create httpexpect instance that will call fasthtpp.RequestHandler directly
|
||||
e := httpexpect.WithConfig(httpexpect.Config{
|
||||
Reporter: httpexpect.NewAssertReporter(t),
|
||||
Client: fasthttpexpect.NewBinder(api.NoListen().Handler),
|
||||
})
|
||||
|
||||
// run the tests
|
||||
for _, r := range routesCustomErrors {
|
||||
e.Request(r.Method, r.RequestPath).
|
||||
|
||||
53
tests/party_test.go
Normal file
53
tests/party_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gavv/httpexpect"
|
||||
"github.com/gavv/httpexpect/fasthttpexpect"
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
func TestSimpleParty(t *testing.T) {
|
||||
h := func(c *iris.Context) { c.WriteString(c.HostString() + c.PathString()) }
|
||||
|
||||
/*
|
||||
// subdomain first, but this test will fail on your machine, so I just commend it, you can imagine what will be
|
||||
party2 := iris.Party("kataras.")
|
||||
{
|
||||
party2.Get("/", h)
|
||||
party2.Get("/path1", h)
|
||||
party2.Get("/path2", h)
|
||||
party2.Get("/namedpath/:param1/something/:param2", h)
|
||||
party2.Get("/namedpath/:param1/something/:param2/else", h)
|
||||
}*/
|
||||
|
||||
// simple
|
||||
party1 := iris.Party("/party1")
|
||||
{
|
||||
party1.Get("/", h)
|
||||
party1.Get("/path1", h)
|
||||
party1.Get("/path2", h)
|
||||
party1.Get("/namedpath/:param1/something/:param2", h)
|
||||
party1.Get("/namedpath/:param1/something/:param2/else", h)
|
||||
}
|
||||
|
||||
// create httpexpect instance that will call fasthtpp.RequestHandler directly
|
||||
e := httpexpect.WithConfig(httpexpect.Config{
|
||||
Reporter: httpexpect.NewAssertReporter(t),
|
||||
Client: fasthttpexpect.NewBinder(iris.NoListen().Handler),
|
||||
})
|
||||
|
||||
request := func(reqPath string) {
|
||||
e.Request("GET", reqPath).
|
||||
Expect().
|
||||
Status(iris.StatusOK).Body().Equal(reqPath)
|
||||
}
|
||||
|
||||
// run the tests
|
||||
request("/party1/")
|
||||
request("/party1/path1")
|
||||
request("/party1/path2")
|
||||
request("/party1/namedpath/theparam1/something/theparam2")
|
||||
request("/party1/namedpath/theparam1/something/theparam2/else")
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/gavv/httpexpect"
|
||||
"github.com/gavv/httpexpect/fasthttpexpect"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/config"
|
||||
)
|
||||
|
||||
type param struct {
|
||||
@@ -59,7 +58,6 @@ var routes = []route{
|
||||
|
||||
func TestRouter(t *testing.T) {
|
||||
api := iris.New()
|
||||
|
||||
for idx := range routes {
|
||||
r := routes[idx]
|
||||
if r.Register {
|
||||
@@ -88,11 +86,10 @@ func TestRouter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
api.PreListen(config.Server{ListeningAddr: ""})
|
||||
// create httpexpect instance that will call fasthtpp.RequestHandler directly
|
||||
e := httpexpect.WithConfig(httpexpect.Config{
|
||||
Reporter: httpexpect.NewAssertReporter(t),
|
||||
Client: fasthttpexpect.NewBinder(api.ServeRequest),
|
||||
Client: fasthttpexpect.NewBinder(api.NoListen().Handler),
|
||||
})
|
||||
|
||||
// run the tests (1)
|
||||
@@ -107,15 +104,14 @@ func TestRouter(t *testing.T) {
|
||||
|
||||
func TestPathEscape(t *testing.T) {
|
||||
api := iris.New()
|
||||
|
||||
api.Get("/details/:name", func(ctx *iris.Context) {
|
||||
name := ctx.Param("name")
|
||||
highlight := ctx.URLParam("highlight")
|
||||
ctx.Text(iris.StatusOK, fmt.Sprintf("name=%s,highlight=%s", name, highlight))
|
||||
})
|
||||
|
||||
api.PreListen(config.Server{ListeningAddr: ""})
|
||||
api.PostListen()
|
||||
e := httpexpect.WithConfig(httpexpect.Config{Reporter: httpexpect.NewAssertReporter(t), Client: fasthttpexpect.NewBinder(api.ServeRequest)})
|
||||
e := httpexpect.WithConfig(httpexpect.Config{Reporter: httpexpect.NewAssertReporter(t), Client: fasthttpexpect.NewBinder(api.NoListen().Handler)})
|
||||
|
||||
e.Request("GET", "/details/Sakamoto desu ga?highlight=text").Expect().Status(iris.StatusOK).Body().Equal("name=Sakamoto desu ga,highlight=text")
|
||||
}
|
||||
Reference in New Issue
Block a user