diff --git a/internal/client/route_list.go b/internal/client/route_list.go index bd08260..eae8f6c 100644 --- a/internal/client/route_list.go +++ b/internal/client/route_list.go @@ -8,6 +8,7 @@ import ( // ListRoutes queries the kapow! instance for the routes that are registered func ListRoutes(host string, w io.Writer) error { + url := host + "/routes/" return http.Get(url, "", nil, w) } diff --git a/internal/client/route_list_test.go b/internal/client/route_list_test.go index c08e9fd..2cd4178 100644 --- a/internal/client/route_list_test.go +++ b/internal/client/route_list_test.go @@ -25,6 +25,10 @@ func TestListRoutesEmpty(t *testing.T) { if err != nil { t.Errorf("%s: unexpected error %q", descr, err) } + + if !gock.IsDone() { + t.Errorf("No endpoint called") + } } func TestListRoutesSome(t *testing.T) { @@ -45,4 +49,8 @@ func TestListRoutesSome(t *testing.T) { } else if got := buf.String(); got != want { t.Errorf("%s: got %q, expected %q", descr, buf, want) } + + if !gock.IsDone() { + t.Errorf("No endpoint called") + } } diff --git a/internal/client/route_remove.go b/internal/client/route_remove.go index bf0fbef..72482ee 100644 --- a/internal/client/route_remove.go +++ b/internal/client/route_remove.go @@ -4,7 +4,9 @@ import ( "github.com/BBVA/kapow/internal/http" ) +// RemoveRoute removes a registered route in Kapow! server func RemoveRoute(host, id string) error { + url := host + "/routes/" + id - return http.Delete(url, "application/json", nil, nil) + return http.Delete(url, "", nil, nil) } diff --git a/internal/client/route_remove_test.go b/internal/client/route_remove_test.go index 4095b02..b3cef53 100644 --- a/internal/client/route_remove_test.go +++ b/internal/client/route_remove_test.go @@ -14,12 +14,16 @@ func TestRemoveRouteExistent(t *testing.T) { ) defer gock.Off() - gock.New(host).Delete("/routes/" + routeID).MatchType("json").Reply(http.StatusNoContent) + gock.New(host).Delete("/routes/" + routeID).Reply(http.StatusNoContent) err := RemoveRoute(host, routeID) if err != nil { t.Errorf("unexpected error: ‘%s’", err) } + + if !gock.IsDone() { + t.Errorf("No endpoint called") + } } func TestRemoveRouteNonExistent(t *testing.T) { @@ -38,4 +42,8 @@ func TestRemoveRouteNonExistent(t *testing.T) { } else if err.Error() != expected { t.Errorf("error mismatch: expected ‘%s’, got ‘%s’", expected, err) } + + if !gock.IsDone() { + t.Errorf("No endpoint called") + } } diff --git a/internal/client/set.go b/internal/client/set.go index 28d6380..5db8ab9 100644 --- a/internal/client/set.go +++ b/internal/client/set.go @@ -6,7 +6,8 @@ import ( "github.com/BBVA/kapow/internal/http" ) -// TODO: Review spec: Data API > Error responses > 204 Resource Item Not Found should not be 2xx -func SetData(kapowURL, handlerId, path string, r io.Reader) error { - return http.Put(kapowURL+"/"+handlerId+path, "", r, nil) +func SetData(host, handlerID, path string, r io.Reader) error { + + url := host + "/handlers/" + handlerID + path + return http.Put(url, "", r, nil) } diff --git a/internal/client/set_test.go b/internal/client/set_test.go index 8c4a39a..e4be385 100644 --- a/internal/client/set_test.go +++ b/internal/client/set_test.go @@ -5,64 +5,18 @@ import ( "strings" "testing" - "github.com/BBVA/kapow/internal/client" - gock "gopkg.in/h2non/gock.v1" + + "github.com/BBVA/kapow/internal/client" ) -// Test that no content errors are detected as non-existent resource -func TestNoContent(t *testing.T) { - expectedErr := "Resource Item Not Found" - host := "http://localhost:8080" - hid := "xxxxxxxxxxxxxx" - path := "/unpath" - reader := strings.NewReader("Esto es un peacho de dato pa repartir") - - defer gock.Off() - - gock.New(host).Put("/" + hid + path).Reply(http.StatusNoContent) - - if err := client.SetData(host, hid, path, reader); err == nil { - t.Error("Expected error not present") - } else if err.Error() != expectedErr { - t.Errorf("Error don't match: expected \"%s\", got \"%s\"", expectedErr, err.Error()) - } - - if !gock.IsDone() { - t.Errorf("No endpoint called") - } -} - -// Test that bad request errors are detected as invalid resource -func TestBadRequest(t *testing.T) { - expectedErr := "Invalid Resource Path" - host := "http://localhost:8080" - hid := "xxxxxxxxxxxxxx" - path := "/unpath" - reader := strings.NewReader("Esto es un peacho de dato pa repartir") - - defer gock.Off() - - gock.New(host).Put("/" + hid + path).Reply(http.StatusBadRequest) - - if err := client.SetData(host, hid, path, reader); err == nil { - t.Error("Expected error not present") - } else if err.Error() != expectedErr { - t.Errorf("Error don't match: expected \"%s\", got \"%s\"", expectedErr, err.Error()) - } - - if !gock.IsDone() { - t.Errorf("No endpoint called") - } -} - // Test that not found errors are detected as invalid handler id func TestNotFound(t *testing.T) { expectedErr := "Not Found" host := "http://localhost:8080" - hid := "xxxxxxxxxxxxxx" - path := "/unpath" - reader := strings.NewReader("Esto es un peacho de dato pa repartir") + hid := "inventedID" + path := "/response/status/code" + reader := strings.NewReader("200") defer gock.Off() @@ -79,33 +33,10 @@ func TestNotFound(t *testing.T) { } } -// Test that internal server errors are detected correctly -func TestInternalServerError(t *testing.T) { - expectedErr := "Internal Server Error" - host := "http://localhost:8080" - hid := "xxxxxxxxxxxxxx" - path := "/unpath" - reader := strings.NewReader("Esto es un peacho de dato pa repartir") - - defer gock.Off() - - gock.New(host).Put("/" + hid + path).Reply(http.StatusInternalServerError) - - if err := client.SetData(host, hid, path, reader); err == nil { - t.Error("Expected error not present") - } else if err.Error() != expectedErr { - t.Errorf("Error don't match: expected \"%s\", got \"%s\"", expectedErr, err.Error()) - } - - if !gock.IsDone() { - t.Errorf("No endpoint called") - } -} - // Test a http ok request func TestOkRequest(t *testing.T) { host := "http://localhost:8080" - hid := "xxxxxxxxxxxxxx" + hid := "HANDLER_XXXXXXXXXXXX" path := "/response/status/code" reader := strings.NewReader("200")