Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey authored Aug 2, 2022
2 parents fd3b613 + 366cc54 commit 60b2e04
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 55 deletions.
14 changes: 9 additions & 5 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
}
}

Expand Down
11 changes: 10 additions & 1 deletion api/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion api/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 60b2e04

Please sign in to comment.