Skip to content

Instantly share code, notes, and snippets.

@rodrigo-brito
Last active September 25, 2017 11:53
Show Gist options
  • Save rodrigo-brito/5b5fd29b0eb9fef9920017c414e8e498 to your computer and use it in GitHub Desktop.
Save rodrigo-brito/5b5fd29b0eb9fef9920017c414e8e498 to your computer and use it in GitHub Desktop.
// 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