From b9bf78abf49031c3e9c8eff1dd8c2bb0e1c7d34e Mon Sep 17 00:00:00 2001 From: pancho horrillo Date: Fri, 4 Oct 2019 06:28:17 +0200 Subject: [PATCH] Fix route_add{,_test}.go to use an io.Writer for saving the response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add a TODO regarding untested response payload. Co-authored-by: Héctor Hurtado --- internal/client/route_add.go | 6 ++++-- internal/client/route_add_test.go | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/client/route_add.go b/internal/client/route_add.go index 78ecfc1..378f2cb 100644 --- a/internal/client/route_add.go +++ b/internal/client/route_add.go @@ -3,16 +3,18 @@ package client import ( "bytes" "encoding/json" + "io" + "github.com/BBVA/kapow/internal/http" ) // AddRoute will add a new route in kapow -func AddRoute(host, path, method, entrypoint, command string) error { +func AddRoute(host, path, method, entrypoint, command string, w io.Writer) error { url := host + "/routes" body, _ := json.Marshal(map[string]string{ "method": method, "url_pattern": path, "entrypoint": entrypoint, "command": command}) - return http.Put(url, "application/json", bytes.NewReader(body), nil) + return http.Put(url, "application/json", bytes.NewReader(body), w) } diff --git a/internal/client/route_add_test.go b/internal/client/route_add_test.go index a4626dd..6f59185 100644 --- a/internal/client/route_add_test.go +++ b/internal/client/route_add_test.go @@ -21,7 +21,10 @@ func TestSuccessOnCorrectRoute(t *testing.T) { Reply(http.StatusCreated). JSON(map[string]string{}) - err := AddRoute("http://localhost", "/hello", "GET", "", "echo Hello World | kapow set /response/body") + // TODO: As per the spec¹, the call should return a JSON body with the info of the new route + // We should consider this in the mocked server and in the test + // ¹: https://github.com/BBVA/kapow/tree/master/spec#insert-a-route + err := AddRoute("http://localhost", "/hello", "GET", "", "echo Hello World | kapow set /response/body", nil) if err != nil { t.Errorf("Unexpected error: %s", err) }