diff --git a/api/rest/client.go b/api/rest/client.go index 9b06d97a2..1167a9481 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -12,6 +12,7 @@ import ( "time" "github.com/CircleCI-Public/circleci-cli/api/header" + "github.com/CircleCI-Public/circleci-cli/settings" "github.com/CircleCI-Public/circleci-cli/version" ) @@ -21,19 +22,22 @@ type Client struct { client *http.Client } -func New(host, endpoint, circleToken string) *Client { +func New(host string, config *settings.Config) *Client { // Ensure endpoint ends with a slash + endpoint := config.RestEndpoint if !strings.HasSuffix(endpoint, "/") { endpoint += "/" } u, _ := url.Parse(host) + + client := config.HTTPClient + client.Timeout = 10 * time.Second + return &Client{ baseURL: u.ResolveReference(&url.URL{Path: endpoint}), - circleToken: circleToken, - client: &http.Client{ - Timeout: 10 * time.Second, - }, + circleToken: config.Token, + client: client, } } diff --git a/api/rest/client_test.go b/api/rest/client_test.go index 619dc87ea..b4761cac2 100644 --- a/api/rest/client_test.go +++ b/api/rest/client_test.go @@ -12,6 +12,7 @@ import ( "gotest.tools/v3/assert" "gotest.tools/v3/assert/cmp" + "github.com/CircleCI-Public/circleci-cli/settings" "github.com/CircleCI-Public/circleci-cli/version" ) @@ -167,5 +168,13 @@ func (f *fixture) Run(statusCode int, respBody string) (c *Client, cleanup func( }) server := httptest.NewServer(mux) - return New(server.URL, "api/v2", "fake-token"), server.Close + cfg := &settings.Config{ + Debug: false, + Token: "fake-token", + RestEndpoint: "api/v2", + Endpoint: "api/v2", + HTTPClient: http.DefaultClient, + } + + return New(server.URL, cfg), server.Close } diff --git a/api/runner/runner_test.go b/api/runner/runner_test.go index dd25a0d4b..77d9dcfe6 100644 --- a/api/runner/runner_test.go +++ b/api/runner/runner_test.go @@ -14,6 +14,7 @@ import ( "gotest.tools/v3/assert/cmp" "github.com/CircleCI-Public/circleci-cli/api/rest" + "github.com/CircleCI-Public/circleci-cli/settings" "github.com/CircleCI-Public/circleci-cli/version" ) @@ -489,5 +490,13 @@ func (f *fixture) Run(statusCode int, respBody string) (r *Runner, cleanup func( }) server := httptest.NewServer(mux) - return New(rest.New(server.URL, "api/v2", "fake-token")), server.Close + cfg := &settings.Config{ + Debug: false, + Token: "fake-token", + RestEndpoint: "api/v2", + Endpoint: "api/v2", + HTTPClient: http.DefaultClient, + } + + return New(rest.New(server.URL, cfg)), server.Close } diff --git a/cmd/runner/runner.go b/cmd/runner/runner.go index 436fc2792..fd647c6d7 100644 --- a/cmd/runner/runner.go +++ b/cmd/runner/runner.go @@ -27,7 +27,7 @@ func NewCommand(config *settings.Config, preRunE validator.Validator) *cobra.Com } else { host = config.Host } - opts.r = runner.New(rest.New(host, config.RestEndpoint, config.Token)) + opts.r = runner.New(rest.New(host, config)) }, }