Skip to content

Commit 997311e

Browse files
test(deploy): fix remaining mig-068 mock sites — full-row helper + MarkBuilding SQL
Two more mock sites still on the pre-068 shape, surfaced by the model/handler *_Branches + redeploy-CASMiss tests: - coverage_provision_gate_test.go: deploymentMockCols() + deploymentMockRow() (the shared full-deployment mock used by every models *_Branches test) now include last_activity_at / scaled_to_zero / always_on (33 cols, matching scanDeployment) — fixes the "expected 30 destination arguments, not 33" Scan errors in TestGetDeploymentByAppID/ByID/ByTeam/...Branches. - MarkDeploymentBuilding's SQL now also sets scaled_to_zero=false + last_activity_at=now() on redeploy (a redeploy is activity + brings replicas back to 1). Update the ExpectExec regexes that pinned the old SQL: 2 in coverage_deployment_test.go, 5 in deploy_redeploy_inplace_mock_test.go. Completes the rule-16 enumeration of every deployments-row mock site rippled by migration 068. Test-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b0ac2ba commit 997311e

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

internal/handlers/deploy_redeploy_inplace_mock_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func TestDeployNew_Redeploy_UpdateStatusError_StillAccepts(t *testing.T) {
338338
// non-determinate (we can't tell whether the flip landed), and
339339
// runRedeployAsync will reconcile the row later. Only an explicit 0-row
340340
// CAS miss means "reaped concurrently, return 409".
341-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
341+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
342342
WithArgs(rowID).
343343
WillReturnError(errMockRedeployDriver)
344344

@@ -494,7 +494,7 @@ func TestDeployNew_Redeploy_CASMiss_Returns409(t *testing.T) {
494494
))
495495

496496
// Guarded CAS matches 0 rows — the reaper won the race. Handler 409s.
497-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
497+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
498498
WithArgs(rowID).
499499
WillReturnResult(sqlmock.NewResult(0, 0))
500500

@@ -606,7 +606,7 @@ func TestDeployRedeploy_ByID_CASMiss_Returns409(t *testing.T) {
606606
))
607607

608608
// Guarded CAS matches 0 rows — the reaper won the race after the read.
609-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
609+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
610610
WithArgs(rowID).
611611
WillReturnResult(sqlmock.NewResult(0, 0))
612612

@@ -661,7 +661,7 @@ func TestDeployRedeploy_ByID_CASSuccess_Returns202(t *testing.T) {
661661
sql.NullTime{}, false, false,
662662
))
663663

664-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
664+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
665665
WithArgs(rowID).
666666
WillReturnResult(sqlmock.NewResult(0, 1))
667667

@@ -713,7 +713,7 @@ func TestDeployRedeploy_ByID_CASDriverError_StillAccepts(t *testing.T) {
713713
))
714714

715715
// Guarded CAS → driver error (non-determinate). Handler logs + continues.
716-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
716+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
717717
WithArgs(rowID).
718718
WillReturnError(errMockRedeployDriver)
719719

internal/models/coverage_deployment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ func TestMarkDeploymentBuilding_Branches(t *testing.T) {
351351

352352
// 1 row matched — redeployable status flipped to building.
353353
db, mock := newMock(t)
354-
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
354+
mock.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
355355
WillReturnResult(sqlmock.NewResult(0, 1))
356356
n, err := MarkDeploymentBuilding(ctx, db, uuid.New())
357357
require.NoError(t, err)
358358
require.Equal(t, int64(1), n)
359359

360360
// 0 rows matched — the row was reaped to a terminal status; CAS no-op.
361361
db2, mock2 := newMock(t)
362-
mock2.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL, updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
362+
mock2.ExpectExec(`UPDATE deployments\s+SET status = 'building', error_message = NULL,\s+scaled_to_zero = false, last_activity_at = now\(\),\s+updated_at = now\(\)\s+WHERE id = \$1 AND status IN`).
363363
WillReturnResult(sqlmock.NewResult(0, 0))
364364
n, err = MarkDeploymentBuilding(ctx, db2, uuid.New())
365365
require.NoError(t, err)

internal/models/coverage_provision_gate_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func deploymentMockCols() []string {
1919
"expires_at", "ttl_policy", "reminders_sent", "last_reminder_at",
2020
"source", "image_ref", "registry_creds_enc",
2121
"git_url", "git_ref", "git_token_enc",
22+
"last_activity_at", "scaled_to_zero", "always_on",
2223
}
2324
}
2425

@@ -30,6 +31,7 @@ func deploymentMockRow() *sqlmock.Rows {
3031
nil, "auto_24h", 0, nil,
3132
"tarball", "", "", // source, image_ref, registry_creds_enc (mig 064)
3233
"", "", "", // git_url, git_ref, git_token_enc (mig 065)
34+
nil, false, false, // last_activity_at, scaled_to_zero, always_on (mig 068)
3335
)
3436
}
3537

0 commit comments

Comments
 (0)