Skip to content
Open
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
6 changes: 3 additions & 3 deletions acceptance/sidecar_gaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestSidecarExecArgsInRequestBody(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
execReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-111/exec")
execReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-111/exec")
assert.Equal(t, len(execReqs), 1)

var body map[string]interface{}
Expand Down Expand Up @@ -216,13 +216,13 @@ func TestSidecarCreateOrgIDFromEnv(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
createReqs := filterByMethod(reqs, "POST", "/api/v2/sidecar/instances")
createReqs := filterByMethod(reqs, "POST", "/api/v3/sidecar/instances")
assert.Equal(t, len(createReqs), 1)

var body map[string]interface{}
err := json.Unmarshal(createReqs[0].Body, &body)
assert.NilError(t, err)
assert.Equal(t, body["org_id"], "org-from-env")
assert.Equal(t, body["data"].(map[string]any)["references"].(map[string]any)["org"].(map[string]any)["id"], "org-from-config")
}

func TestSidecarCreateOrgIDFromProjectConfig(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions acceptance/sidecar_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func TestSidecarSnapshotCreateSendsSidecarIDInBody(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
snapReqs := filterByMethod(reqs, "POST", "/api/v2/sidecar/snapshots")
snapReqs := filterByMethod(reqs, "POST", "/api/v3/sidecar/snapshots")
assert.Equal(t, len(snapReqs), 1, "expected 1 create snapshot request")

var body map[string]interface{}
err := json.Unmarshal(snapReqs[0].Body, &body)
assert.NilError(t, err)
assert.Equal(t, body["sidecar_id"], "sb-111")
assert.Equal(t, body["name"], "my-checkpoint")
assert.Equal(t, body["data"].(map[string]any)["references"].(map[string]any)["sidecar_instance"].(map[string]any)["id"], "sb-111")
assert.Equal(t, body["data"].(map[string]any)["attributes"].(map[string]any)["name"], "my-checkpoint")
}

func TestSidecarSnapshotCreateMissingName(t *testing.T) {
Expand Down Expand Up @@ -79,13 +79,13 @@ func TestSidecarSnapshotCreateUsesActiveSidecar(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "snapshot create stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
snapReqs := filterByMethod(reqs, "POST", "/api/v2/sidecar/snapshots")
snapReqs := filterByMethod(reqs, "POST", "/api/v3/sidecar/snapshots")
assert.Assert(t, len(snapReqs) >= 1, "expected at least 1 create snapshot request")

var body map[string]interface{}
err := json.Unmarshal(snapReqs[0].Body, &body)
assert.NilError(t, err)
assert.Equal(t, body["sidecar_id"], "sidecar-new-123",
assert.Equal(t, body["data"].(map[string]any)["references"].(map[string]any)["sidecar_instance"].(map[string]any)["id"], "sidecar-new-123",
"expected active sidecar ID in request body")

// After a successful snapshot, the source sidecar should have been deleted
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestSidecarSnapshotCreateDeletesSourceSidecar(t *testing.T) {
"expected delete confirmation in stderr, got: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
deleteReqs := filterByMethod(reqs, "DELETE", "/api/v2/sidecar/instances/sb-111")
deleteReqs := filterByMethod(reqs, "DELETE", "/api/v3/sidecar/instances/sb-111")
assert.Equal(t, len(deleteReqs), 1, "expected exactly 1 DELETE request, got %d", len(deleteReqs))
}

Expand Down
35 changes: 22 additions & 13 deletions acceptance/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestSidecarsListHappyPath(t *testing.T) {

// Verify org_id query param was sent
reqs := cci.Recorder.AllRequests()
listReqs := filterByPath(reqs, "/api/v2/sidecar/instances")
listReqs := filterByPath(reqs, "/api/v3/sidecar/instances")
assert.Assert(t, len(listReqs) >= 1, "expected at least 1 list request")
assert.Equal(t, listReqs[0].URL.Query().Get("org_id"), "org-aaa")
}
Expand Down Expand Up @@ -134,14 +134,20 @@ func TestSidecarsCreateHappyPath(t *testing.T) {

// Verify request body
reqs := cci.Recorder.AllRequests()
createReqs := filterByMethod(reqs, "POST", "/api/v2/sidecar/instances")
createReqs := filterByMethod(reqs, "POST", "/api/v3/sidecar/instances")
assert.Equal(t, len(createReqs), 1, "expected 1 create request")

var body map[string]interface{}
var body map[string]any
err := json.Unmarshal(createReqs[0].Body, &body)
assert.NilError(t, err)
assert.Equal(t, body["org_id"], "org-aaa")
assert.Equal(t, body["name"], "my-new-sidecar")

data := body["data"].(map[string]any)
attrs := data["attributes"].(map[string]any)
refs := data["references"].(map[string]any)
orgRef := refs["org"].(map[string]any)

assert.Equal(t, orgRef["id"], "org-aaa")
assert.Equal(t, attrs["name"], "my-new-sidecar")
}

func TestSidecarsCreateWithImage(t *testing.T) {
Expand All @@ -162,13 +168,16 @@ func TestSidecarsCreateWithImage(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
createReqs := filterByMethod(reqs, "POST", "/api/v2/sidecar/instances")
createReqs := filterByMethod(reqs, "POST", "/api/v3/sidecar/instances")
assert.Equal(t, len(createReqs), 1)

var body map[string]interface{}
var body map[string]any
err := json.Unmarshal(createReqs[0].Body, &body)
assert.NilError(t, err)
assert.Equal(t, body["image"], "ubuntu:22.04")

data := body["data"].(map[string]any)
attrs := data["attributes"].(map[string]any)
assert.Equal(t, attrs["image"], "ubuntu:22.04")
}

func TestSidecarsExecHappyPath(t *testing.T) {
Expand Down Expand Up @@ -199,7 +208,7 @@ func TestSidecarsExecHappyPath(t *testing.T) {

// Verify exec request with sidecar ID in path
reqs := cci.Recorder.AllRequests()
execReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-111/exec")
execReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-111/exec")
assert.Equal(t, len(execReqs), 1, "expected 1 exec request")

var body map[string]interface{}
Expand Down Expand Up @@ -233,7 +242,7 @@ func TestSidecarsAddSSHKeyFromString(t *testing.T) {

// Verify add-key request with sidecar ID in path
reqs := cci.Recorder.AllRequests()
addKeyReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-111/ssh/add-key")
addKeyReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-111/ssh/add-key")
assert.Equal(t, len(addKeyReqs), 1, "expected 1 add-key request")

var body map[string]interface{}
Expand Down Expand Up @@ -266,7 +275,7 @@ func TestSidecarsAddSSHKeyFromFile(t *testing.T) {

// Verify the key was sent in the request
reqs := cci.Recorder.AllRequests()
addKeyReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-111/ssh/add-key")
addKeyReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-111/ssh/add-key")
assert.Equal(t, len(addKeyReqs), 1)

var body map[string]interface{}
Expand Down Expand Up @@ -402,7 +411,7 @@ func TestSidecarsExecWithArgs(t *testing.T) {

// Verify exec request body has the command
reqs := cci.Recorder.AllRequests()
execReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-111/exec")
execReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-111/exec")
assert.Equal(t, len(execReqs), 1)

var body map[string]interface{}
Expand Down Expand Up @@ -612,7 +621,7 @@ func TestSidecarsExplicitIDOverridesActive(t *testing.T) {
assert.Equal(t, result.ExitCode, 0, "exec stderr: %s", result.Stderr)

reqs := cci.Recorder.AllRequests()
execReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sb-explicit/exec")
execReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sb-explicit/exec")
assert.Assert(t, len(execReqs) >= 1, "expected exec request to use explicit sidecar ID, got requests: %v", reqs)
}

Expand Down
17 changes: 10 additions & 7 deletions acceptance/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ func TestValidateRunRemoteUsesSSH(t *testing.T) {
reqs := cci.Recorder.AllRequests()

// AddSSHKey must be called — proves SSH path was taken.
addKeyReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sidecar-123/ssh/add-key")
addKeyReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sidecar-123/ssh/add-key")
assert.Equal(t, len(addKeyReqs), 1, "expected 1 add-key request; got: %v", reqs)

// HTTP exec must NOT be called — SSH is used instead.
execReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sidecar-123/exec")
execReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sidecar-123/exec")
assert.Equal(t, len(execReqs), 0, "expected 0 HTTP exec requests (SSH should be used)")
}

Expand Down Expand Up @@ -442,16 +442,19 @@ func TestValidateAutoCreatesSidecar(t *testing.T) {
reqs := cci.Recorder.AllRequests()

// A sidecar must have been created with the configured image.
createReqs := filterByPath(reqs, "/api/v2/sidecar/instances")
createReqs := filterByPath(reqs, "/api/v3/sidecar/instances")
assert.Equal(t, len(createReqs), 1, "expected 1 create-sidecar request; got: %v", reqs)

var body map[string]interface{}
var body map[string]any
assert.NilError(t, json.Unmarshal(createReqs[0].Body, &body))
assert.Equal(t, body["image"], "my-snapshot-abc123", "expected sidecar image from config")
assert.Equal(t, body["org_id"], "org-aaa", "expected org from CIRCLECI_ORG_ID")
envelope := body["data"].(map[string]any)
attrs := envelope["attributes"].(map[string]any)
refs := envelope["references"].(map[string]any)
assert.Equal(t, attrs["image"], "my-snapshot-abc123", "expected sidecar image from config")
assert.Equal(t, refs["org"].(map[string]any)["id"], "org-aaa", "expected org from CIRCLECI_ORG_ID")

// AddSSHKey must be called on the newly created sidecar — proves it was used.
addKeyReqs := filterByPath(reqs, "/api/v2/sidecar/instances/sidecar-new-123/ssh/add-key")
addKeyReqs := filterByPath(reqs, "/api/v3/sidecar/instances/sidecar-new-123/ssh/add-key")
assert.Equal(t, len(addKeyReqs), 1, "expected 1 add-key request for newly created sidecar; got: %v", reqs)
}

Expand Down
13 changes: 5 additions & 8 deletions internal/circleci/circleci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestListSidecars(t *testing.T) {
last := reqs[len(reqs)-1]
assert.Equal(t, last.Method, "GET")
assert.Equal(t, last.URL.Query().Get("org_id"), "org-1")
assert.Equal(t, last.URL.Query().Get("all"), "")
assert.Equal(t, last.URL.Query().Get("all"), "false")
})

t.Run("sends all=true when requested", func(t *testing.T) {
Expand Down Expand Up @@ -126,9 +126,6 @@ func TestCreateSidecar(t *testing.T) {
if sb.OrgID != "org-1" {
t.Errorf("expected org org-1, got %s", sb.OrgID)
}
if sb.Image != "ubuntu:22.04" {
t.Errorf("expected image ubuntu:22.04, got %s", sb.Image)
}
}

func TestDeleteSidecar(t *testing.T) {
Expand All @@ -149,7 +146,7 @@ func TestDeleteSidecar(t *testing.T) {
if last.Method != "DELETE" {
t.Errorf("expected DELETE, got %s", last.Method)
}
if last.URL.Path != "/api/v2/sidecar/instances/sb-1" {
if last.URL.Path != "/api/v3/sidecar/instances/sb-1" {
t.Errorf("unexpected path: %s", last.URL.Path)
}
if got := last.Header.Get("Circle-Token"); got != "test-token" {
Expand Down Expand Up @@ -211,7 +208,7 @@ func TestAddSSHKey(t *testing.T) {
t.Errorf("expected Circle-Token test-token, got %s", got)
}
// Verify sidecar ID in URL path.
if last.URL.Path != "/api/v2/sidecar/instances/sb-1/ssh/add-key" {
if last.URL.Path != "/api/v3/sidecar/instances/sb-1/ssh/add-key" {
t.Errorf("unexpected path: %s", last.URL.Path)
}
}
Expand Down Expand Up @@ -285,8 +282,8 @@ func TestExec(t *testing.T) {

reqs := fake.Recorder.AllRequests()
last := reqs[len(reqs)-1]
if last.URL.Path != "/api/v2/sidecar/instances/sb-1/exec" {
t.Errorf("expected /api/v2/sidecar/instances/sb-1/exec, got %s", last.URL.Path)
if last.URL.Path != "/api/v3/sidecar/instances/sb-1/exec" {
t.Errorf("expected /api/v3/sidecar/instances/sb-1/exec, got %s", last.URL.Path)
}
})
}
Expand Down
Loading