Last active
September 25, 2017 11:53
-
-
Save rodrigo-brito/5b5fd29b0eb9fef9920017c414e8e498 to your computer and use it in GitHub Desktop.
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
// Router | |
// ----------- | |
func SampleRouter(ctx context.Context) *echo.Echo { | |
e := echo.New() | |
e.Use(defaultMiddlewares(ctx)...) | |
e.Use(em.AddTrailingSlash()) | |
e.GET("/sample/test", echo.WrapHandler(http.HandlerFunc(home.Handle))) //Handle(w http.ResponseWriter, r *http.Request) | |
return e | |
} | |
// TESTS | |
// ----------- | |
var ( | |
server *httptest.Server //import "net/http/httptest" | |
) | |
//Global server suit | |
func init(){ | |
server = httptest.NewServer(router.SampleRouter(ctx)) | |
//init ctx, etc... | |
} | |
func TestHandle(t *testing.T) { | |
expect := httpexpect.New(t, server.URL) //import "github.com/gavv/httpexpect" | |
result := expect.GET("/sample/test").Expect() | |
Convey("It should succeed with http.StatusOK", func() { | |
So(result.Raw().StatusCode, ShouldEqual, http.StatusOK) | |
//Other assertions | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment