From 2005f453c6ca0bfd28fb49e54b107b46fc9421df Mon Sep 17 00:00:00 2001 From: mitchelljfs Date: Sun, 15 Jul 2018 11:41:02 -0700 Subject: [PATCH] Expanded pattern matching cases --- router_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/router_test.go b/router_test.go index c1c23fa..b681803 100644 --- a/router_test.go +++ b/router_test.go @@ -54,7 +54,7 @@ func TestRouterSpec(t *testing.T) { request.HTTPMethod = http.MethodGet request.Path = "/orders/filter" - Convey("The router will return and error body and a not found status", func() { + Convey("The router will return an error body and a status not found", func() { response := rtr.Respond() So(response.StatusCode, ShouldEqual, http.StatusNotFound) @@ -67,6 +67,34 @@ func TestRouterSpec(t *testing.T) { rtr.Get("/orders/filter/by_user/{id}", hdlrfunc) }, ShouldPanicWith, "endpoint already existent") }) + + Convey("And a Get handler expecting the pattern /orders/filter", func() { + rtr.Get("/orders/filter", hdlrfunc) + + Convey("And the request matches the pattern and the path params are filled", func() { + request.HTTPMethod = http.MethodGet + request.Path = "/shipping/orders/filter" + + Convey("The router will return the expected status and body", func() { + response := rtr.Respond() + + So(response.StatusCode, ShouldEqual, http.StatusOK) + So(response.Body, ShouldEqual, "hello") + }) + }) + + Convey("And the request does NOT match either of the patterns", func() { + request.HTTPMethod = http.MethodGet + request.Path = "/shipping/orders/filter/by_user" + + Convey("The router will return an error body and a status not found", func() { + response := rtr.Respond() + + So(response.StatusCode, ShouldEqual, http.StatusNotFound) + So(response.Body, ShouldEqual, "{\"error\":\"no route matching path found\"}") + }) + }) + }) }) })