Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the runner v3 API [ONPREM-237] #1065

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ type runnerOpts struct {
r running
}

func NewCommand(config *settings.Config, preRunE validator.Validator) *cobra.Command {
func NewCommand(rootConfig *settings.Config, preRunE validator.Validator) *cobra.Command {
// The runner API versioning is decoupled from the other Circle APIs. Here we make a copy of the root configuration,
// and update the rest endpoint accordingly
config := *rootConfig
config.RestEndpoint = "/api/v3"

var opts runnerOpts
cmd := &cobra.Command{
Use: "runner",
Expand All @@ -27,7 +32,7 @@ func NewCommand(config *settings.Config, preRunE validator.Validator) *cobra.Com
} else {
host = config.Host
}
opts.r = runner.New(rest.NewFromConfig(host, config))
opts.r = runner.New(rest.NewFromConfig(host, &config))
},
}

Expand Down
31 changes: 31 additions & 0 deletions cmd/runner/runner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package runner

import (
"net/http"
"net/http/httptest"
"testing"

"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"

"github.com/CircleCI-Public/circleci-cli/settings"
)

func Test_NewCommand(t *testing.T) {
t.Run("Runner uses /api/v3", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Check(t, cmp.Equal(r.URL.EscapedPath(), "/api/v3/runner"))

w.Header().Set("Content-Type", "application/json")
_, err := w.Write([]byte(`{"items":[]}`))
assert.NilError(t, err)
w.WriteHeader(http.StatusOK)
}))
t.Cleanup(server.Close)

cmd := NewCommand(&settings.Config{Host: server.URL, HTTPClient: &http.Client{}}, nil)
cmd.SetArgs([]string{"instance", "ls", "my-namespace"})
err := cmd.Execute()
assert.NilError(t, err)
})
}