From 04c239246a42d2b1ff8b3485af91a1f89e1008a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Wed, 25 Nov 2020 13:38:37 +0100 Subject: [PATCH] internal/test: remove redundant API interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test.API is actually just http.Handler, let's use this interface directly instead of defining our own one. Signed-off-by: Ondřej Budai --- internal/test/helpers.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/internal/test/helpers.go b/internal/test/helpers.go index 634476ee6..020f9c2cb 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -22,10 +22,6 @@ import ( "github.com/stretchr/testify/require" ) -type API interface { - ServeHTTP(writer http.ResponseWriter, request *http.Request) -} - func externalRequest(method, path, body string) *http.Response { client := http.Client{ Transport: &http.Transport{ @@ -52,7 +48,7 @@ func externalRequest(method, path, body string) *http.Response { return resp } -func internalRequest(api API, method, path, body string) *http.Response { +func internalRequest(api http.Handler, method, path, body string) *http.Response { req := httptest.NewRequest(method, path, bytes.NewReader([]byte(body))) req.Header.Set("Content-Type", "application/json") resp := httptest.NewRecorder() @@ -61,7 +57,7 @@ func internalRequest(api API, method, path, body string) *http.Response { return resp.Result() } -func SendHTTP(api API, external bool, method, path, body string) *http.Response { +func SendHTTP(api http.Handler, external bool, method, path, body string) *http.Response { if len(os.Getenv("OSBUILD_COMPOSER_TEST_EXTERNAL")) > 0 { if !external { return nil @@ -102,7 +98,7 @@ func dropFields(obj interface{}, fields ...string) { } } -func TestRoute(t *testing.T, api API, external bool, method, path, body string, expectedStatus int, expectedJSON string, ignoreFields ...string) { +func TestRoute(t *testing.T, api http.Handler, external bool, method, path, body string, expectedStatus int, expectedJSON string, ignoreFields ...string) { t.Helper() resp := SendHTTP(api, external, method, path, body) @@ -140,7 +136,7 @@ func TestRoute(t *testing.T, api API, external bool, method, path, body string, require.Equal(t, expected, reply) } -func TestTOMLRoute(t *testing.T, api API, external bool, method, path, body string, expectedStatus int, expectedTOML string, ignoreFields ...string) { +func TestTOMLRoute(t *testing.T, api http.Handler, external bool, method, path, body string, expectedStatus int, expectedTOML string, ignoreFields ...string) { t.Helper() resp := SendHTTP(api, external, method, path, body) @@ -174,7 +170,7 @@ func TestTOMLRoute(t *testing.T, api API, external bool, method, path, body stri require.Equal(t, expected, reply) } -func TestNonJsonRoute(t *testing.T, api API, external bool, method, path, body string, expectedStatus int, expectedResponse string) { +func TestNonJsonRoute(t *testing.T, api http.Handler, external bool, method, path, body string, expectedStatus int, expectedResponse string) { response := SendHTTP(api, external, method, path, body) assert.Equalf(t, expectedStatus, response.StatusCode, "%s: status mismatch", path)