From 8c3cd245d8dcb72f31ed1328689bfd9845c84213 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 24 Oct 2019 13:23:49 +0200 Subject: [PATCH] weldr/test: split out sendHTTP helper method This simplifies the code a bit, and will be used in follow-up patches to distinguish between setup calls and explicit tests. Signed-off-by: Tom Gundersen --- internal/weldr/api_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 814713aa0..b38077bbc 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -67,16 +67,21 @@ func internalRequest(api *weldr.API, method, path, body string) *http.Response { return resp.Result() } -func testRoute(t *testing.T, api *weldr.API, external bool, method, path, body string, expectedStatus int, expectedJSON string) { - var resp *http.Response - +func sendHTTP(api *weldr.API, external bool, method, path, body string) *http.Response { if len(os.Getenv("OSBUILD_COMPOSER_TEST_EXTERNAL")) > 0 { if !external { - t.Skip("This test is for internal testing only") + return nil } - resp = externalRequest(method, path, body) + return externalRequest(method, path, body) } else { - resp = internalRequest(api, method, path, body) + return internalRequest(api, method, path, body) + } +} + +func testRoute(t *testing.T, api *weldr.API, external bool, method, path, body string, expectedStatus int, expectedJSON string) { + resp := sendHTTP(api, external, method, path, body) + if resp == nil { + t.Skip("This test is for internal testing only") } if resp.StatusCode != expectedStatus {