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 <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-24 13:23:49 +02:00
parent f055ba2e07
commit 8c3cd245d8

View file

@ -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 {