-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
165 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package example | ||
|
||
import ( | ||
"github.com/labstack/echo" | ||
echofast "github.com/labstack/echo/engine/fasthttp" | ||
echostandard "github.com/labstack/echo/engine/standard" | ||
"github.com/valyala/fasthttp" | ||
"net/http" | ||
) | ||
|
||
// EchoServer creates HTTP server using echo framework. | ||
// | ||
// Implemented API: | ||
// GET /hello print "hello, world" | ||
func EchoServer() *echo.Echo { | ||
ec := echo.New() | ||
|
||
ec.GET("/hello", func(ctx echo.Context) error { | ||
return ctx.String(http.StatusOK, "hello, world!") | ||
}) | ||
|
||
return ec | ||
} | ||
|
||
// EchoHandlerStandard creates http.Handler for EchoServer(). | ||
func EchoHandlerStandard() http.Handler { | ||
server := echostandard.New("") | ||
server.SetHandler(EchoServer()) | ||
return http.Handler(server) | ||
} | ||
|
||
// EchoHandlerFast creates fasthttp.RequestHandler for EchoServer(). | ||
func EchoHandlerFast() fasthttp.RequestHandler { | ||
server := echofast.New("") | ||
server.SetHandler(EchoServer()) | ||
return func(ctx *fasthttp.RequestCtx) { | ||
server.ServeHTTP(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package example | ||
|
||
import ( | ||
"github.com/gavv/httpexpect" | ||
"github.com/gavv/httpexpect/fasthttpexpect" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestEcho_Standard(t *testing.T) { | ||
// create http.Handler | ||
handler := EchoHandlerStandard() | ||
|
||
// create httpexpect instance that will call htpp.Handler directly | ||
e := httpexpect.WithConfig(httpexpect.Config{ | ||
Reporter: httpexpect.NewAssertReporter(t), | ||
Client: httpexpect.NewBinder(handler), | ||
}) | ||
|
||
// run tests | ||
e.GET("/hello"). | ||
Expect(). | ||
Status(http.StatusOK).Body().Equal("hello, world!") | ||
} | ||
|
||
func TestEcho_Fast(t *testing.T) { | ||
// create fasthttp.RequestHandler | ||
handler := EchoHandlerFast() | ||
|
||
// create httpexpect instance that will call fasthtpp.RequestHandler directly | ||
e := httpexpect.WithConfig(httpexpect.Config{ | ||
Reporter: httpexpect.NewAssertReporter(t), | ||
Client: fasthttpexpect.NewBinder(handler), | ||
}) | ||
|
||
// run tests | ||
e.GET("/hello"). | ||
Expect(). | ||
Status(http.StatusOK).Body().Equal("hello, world!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package example is usage example for httpexpect. | ||
package example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters