diff --git a/server/controllers/api_controller.go b/server/controllers/api_controller.go index a595fc940e..d51ffa91ca 100644 --- a/server/controllers/api_controller.go +++ b/server/controllers/api_controller.go @@ -275,7 +275,7 @@ func (a *APIController) apiPlan(request *APIRequest, ctx *command.Context) (*com } } - res := a.ProjectPlanCommandRunner.Plan(cmd) + res := events.RunOneProjectCmd(a.ProjectPlanCommandRunner.Plan, cmd) projectResults = append(projectResults, res) a.PostWorkflowHooksCommandRunner.RunPostHooks(ctx, cc[i]) // nolint: errcheck @@ -323,7 +323,7 @@ func (a *APIController) apiApply(request *APIRequest, ctx *command.Context) (*co } } - res := a.ProjectApplyCommandRunner.Apply(cmd) + res := events.RunOneProjectCmd(a.ProjectApplyCommandRunner.Apply, cmd) projectResults = append(projectResults, res) a.PostWorkflowHooksCommandRunner.RunPostHooks(ctx, cc[i]) // nolint: errcheck diff --git a/server/controllers/api_controller_test.go b/server/controllers/api_controller_test.go index d712b0d64c..51019a3378 100644 --- a/server/controllers/api_controller_test.go +++ b/server/controllers/api_controller_test.go @@ -285,10 +285,10 @@ func setup(t *testing.T) (controllers.APIController, *MockProjectCommandBuilder, }}, nil) projectCommandRunner := NewMockProjectCommandRunner() - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{ + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{ PlanSuccess: &models.PlanSuccess{}, }) - When(projectCommandRunner.Apply(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{ + When(projectCommandRunner.Apply(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{ ApplySuccess: "success", }) diff --git a/server/controllers/locks_controller_test.go b/server/controllers/locks_controller_test.go index 13a523f6d1..e652c5cdcd 100644 --- a/server/controllers/locks_controller_test.go +++ b/server/controllers/locks_controller_test.go @@ -306,9 +306,11 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) { Command: command.Plan, RepoRelDir: projectPath, Workspace: workspaceName, - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "tf-output", - LockURL: "lock-url", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "tf-output", + LockURL: "lock-url", + }, }, }, }) diff --git a/server/core/boltdb/boltdb_test.go b/server/core/boltdb/boltdb_test.go index a3a22169cc..7440fe2419 100644 --- a/server/core/boltdb/boltdb_test.go +++ b/server/core/boltdb/boltdb_test.go @@ -474,7 +474,9 @@ func TestPullStatus_UpdateGet(t *testing.T) { Command: command.Plan, RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -524,7 +526,9 @@ func TestPullStatus_UpdateDeleteGet(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -570,12 +574,16 @@ func TestPullStatus_UpdateProject(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { - RepoRelDir: ".", - Workspace: "staging", - ApplySuccess: "success!", + RepoRelDir: ".", + Workspace: "staging", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) Ok(t, err) @@ -634,7 +642,9 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -643,9 +653,11 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { status, err := b.UpdatePullWithResults(pull, []command.ProjectResult{ { - RepoRelDir: ".", - Workspace: "staging", - ApplySuccess: "success!", + RepoRelDir: ".", + Workspace: "staging", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) @@ -698,24 +710,30 @@ func TestPullStatus_UpdateMerge_Apply(t *testing.T) { Command: command.Plan, RepoRelDir: "mergeme", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Command: command.Plan, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Command: command.Plan, RepoRelDir: "staythesame", Workspace: "default", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "tf out", - LockURL: "lock-url", - RePlanCmd: "plan command", - ApplyCmd: "apply command", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "tf out", + LockURL: "lock-url", + RePlanCmd: "plan command", + ApplyCmd: "apply command", + }, }, }, }) @@ -724,23 +742,29 @@ func TestPullStatus_UpdateMerge_Apply(t *testing.T) { updateStatus, err := b.UpdatePullWithResults(pull, []command.ProjectResult{ { - Command: command.Apply, - RepoRelDir: "mergeme", - Workspace: "default", - ApplySuccess: "applied!", + Command: command.Apply, + RepoRelDir: "mergeme", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "applied!", + }, }, { Command: command.Apply, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Error: errors.New("apply error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("apply error"), + }, }, { - Command: command.Apply, - RepoRelDir: "newresult", - Workspace: "default", - ApplySuccess: "success!", + Command: command.Apply, + RepoRelDir: "newresult", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) Ok(t, err) @@ -811,12 +835,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { Command: command.PolicyCheck, RepoRelDir: "mergeme", Workspace: "default", - Failure: "policy failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "policy failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + }, }, }, }, @@ -826,12 +852,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Failure: "policy failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "policy failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + }, }, }, }, @@ -845,12 +873,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { Command: command.ApprovePolicies, RepoRelDir: "mergeme", Workspace: "default", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, - CurApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + CurApprovals: 1, + }, }, }, }, diff --git a/server/core/redis/redis_test.go b/server/core/redis/redis_test.go index 30c89a4444..7800dffb29 100644 --- a/server/core/redis/redis_test.go +++ b/server/core/redis/redis_test.go @@ -515,7 +515,9 @@ func TestPullStatus_UpdateGet(t *testing.T) { Command: command.Plan, RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -565,7 +567,9 @@ func TestPullStatus_UpdateDeleteGet(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -611,12 +615,16 @@ func TestPullStatus_UpdateProject(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { - RepoRelDir: ".", - Workspace: "staging", - ApplySuccess: "success!", + RepoRelDir: ".", + Workspace: "staging", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) Ok(t, err) @@ -675,7 +683,9 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }) Ok(t, err) @@ -684,9 +694,11 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { status, err := rdb.UpdatePullWithResults(pull, []command.ProjectResult{ { - RepoRelDir: ".", - Workspace: "staging", - ApplySuccess: "success!", + RepoRelDir: ".", + Workspace: "staging", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) @@ -739,24 +751,30 @@ func TestPullStatus_UpdateMerge_Apply(t *testing.T) { Command: command.Plan, RepoRelDir: "mergeme", Workspace: "default", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Command: command.Plan, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Command: command.Plan, RepoRelDir: "staythesame", Workspace: "default", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "tf out", - LockURL: "lock-url", - RePlanCmd: "plan command", - ApplyCmd: "apply command", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "tf out", + LockURL: "lock-url", + RePlanCmd: "plan command", + ApplyCmd: "apply command", + }, }, }, }) @@ -765,23 +783,29 @@ func TestPullStatus_UpdateMerge_Apply(t *testing.T) { updateStatus, err := rdb.UpdatePullWithResults(pull, []command.ProjectResult{ { - Command: command.Apply, - RepoRelDir: "mergeme", - Workspace: "default", - ApplySuccess: "applied!", + Command: command.Apply, + RepoRelDir: "mergeme", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "applied!", + }, }, { Command: command.Apply, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Error: errors.New("apply error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("apply error"), + }, }, { - Command: command.Apply, - RepoRelDir: "newresult", - Workspace: "default", - ApplySuccess: "success!", + Command: command.Apply, + RepoRelDir: "newresult", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success!", + }, }, }) Ok(t, err) @@ -852,12 +876,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { Command: command.PolicyCheck, RepoRelDir: "mergeme", Workspace: "default", - Failure: "policy failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "policy failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + }, }, }, }, @@ -867,12 +893,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", - Failure: "policy failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "policy failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + }, }, }, }, @@ -886,12 +914,14 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) { Command: command.ApprovePolicies, RepoRelDir: "mergeme", Workspace: "default", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - ReqApprovals: 1, - CurApprovals: 1, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + ReqApprovals: 1, + CurApprovals: 1, + }, }, }, }, diff --git a/server/core/runtime/mocks/mock_status_updater.go b/server/core/runtime/mocks/mock_status_updater.go index 8f36ee0d10..6c1df30c44 100644 --- a/server/core/runtime/mocks/mock_status_updater.go +++ b/server/core/runtime/mocks/mock_status_updater.go @@ -26,7 +26,7 @@ func NewMockStatusUpdater(options ...pegomock.Option) *MockStatusUpdater { func (mock *MockStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) error { +func (mock *MockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockStatusUpdater().") } @@ -78,7 +78,7 @@ type VerifierMockStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) *MockStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) *MockStatusUpdater_UpdateProject_OngoingVerification { _params := []pegomock.Param{ctx, cmdName, status, url, res} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", _params, verifier.timeout) return &MockStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -89,12 +89,12 @@ type MockStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string, *command.ProjectResult) { +func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string, *command.ProjectCommandOutput) { ctx, cmdName, status, url, res := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], url[len(url)-1], res[len(res)-1] } -func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectResult) { +func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectCommandOutput) { _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(_params) > 0 { if len(_params) > 0 { @@ -122,9 +122,9 @@ func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArgu } } if len(_params) > 4 { - _param4 = make([]*command.ProjectResult, len(c.methodInvocations)) + _param4 = make([]*command.ProjectCommandOutput, len(c.methodInvocations)) for u, param := range _params[4] { - _param4[u] = param.(*command.ProjectResult) + _param4[u] = param.(*command.ProjectCommandOutput) } } } diff --git a/server/core/runtime/runtime.go b/server/core/runtime/runtime.go index 8438cad69c..e8ede0048b 100644 --- a/server/core/runtime/runtime.go +++ b/server/core/runtime/runtime.go @@ -54,7 +54,7 @@ type AsyncTFExec interface { // //go:generate pegomock generate --package mocks -o mocks/mock_status_updater.go StatusUpdater type StatusUpdater interface { - UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) error + UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) error } // Runner mirrors events.StepRunner as a way to bring it into this package diff --git a/server/events/apply_command_runner_test.go b/server/events/apply_command_runner_test.go index 40ebc8e882..4c65a4c3d8 100644 --- a/server/events/apply_command_runner_test.go +++ b/server/events/apply_command_runner_test.go @@ -231,12 +231,12 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { RegisterMockTestingT(t) cases := []struct { - Description string - ProjectContexts []command.ProjectContext - ProjectResults []command.ProjectResult - RunnerInvokeMatch []*EqMatcher - ExpComment string - ApplyFailed bool + Description string + ProjectContexts []command.ProjectContext + ProjectCommandOutputs []command.ProjectCommandOutput + RunnerInvokeMatch []*EqMatcher + ExpComment string + ApplyFailed bool }{ { Description: "When first apply fails, the second don't run", @@ -254,14 +254,12 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, }, RunnerInvokeMatch: []*EqMatcher{ @@ -270,8 +268,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: true, ExpComment: "Ran Apply for 2 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", }, { Description: "When first apply fails, the second not will run", @@ -289,13 +286,11 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -304,7 +299,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { Never(), }, ApplyFailed: true, - ExpComment: "Ran Apply for dir: `` workspace: ``\n\n**Apply Error**\n```\nshabang\n```", + ExpComment: "Ran Apply for project: `First` dir: `` workspace: ``\n\n**Apply Error**\n```\nshabang\n```", }, { Description: "When both in a group of two succeeds, the following two will run", @@ -331,21 +326,17 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -357,8 +348,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: true, ExpComment: "Ran Apply for 2 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", }, { Description: "When one out of two fails, the following two will not run", @@ -385,21 +375,17 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Fourth", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -411,10 +397,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: true, ExpComment: "Ran Apply for 4 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### " + - "3. dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### " + - "4. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n4 projects, 3 successful, 0 failed, 1 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n1. project: `Third` dir: `` workspace: ``\n1. project: `Fourth` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### 3. project: `Third` dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### 4. project: `Fourth` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n4 projects, 3 successful, 0 failed, 1 errored", }, { Description: "Don't block when parallel is not set", @@ -430,13 +413,11 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -446,8 +427,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: true, ExpComment: "Ran Apply for 2 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", }, { Description: "Don't block when abortOnExecutionOrderFail is not set", @@ -461,13 +441,11 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Second", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -477,8 +455,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: true, ExpComment: "Ran Apply for 2 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n**Apply Error**\n```\nshabang\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 1 successful, 0 failed, 1 errored", }, { Description: "All project finished successfully", @@ -492,13 +469,11 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Second", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Apply, ApplySuccess: "Great success!", }, { - Command: command.Apply, ApplySuccess: "Great success!", }, }, @@ -508,8 +483,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { }, ApplyFailed: false, ExpComment: "Ran Apply for 2 projects:\n\n" + - "1. dir: `` workspace: ``\n1. dir: `` workspace: ``\n---\n\n### 1. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### " + - "2. dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 2 successful, 0 failed, 0 errored", + "1. project: `First` dir: `` workspace: ``\n1. project: `Second` dir: `` workspace: ``\n---\n\n### 1. project: `First` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### 2. project: `Second` dir: `` workspace: ``\n```diff\nGreat success!\n```\n\n---\n### Apply Summary\n\n2 projects, 2 successful, 0 failed, 0 errored", }, } @@ -540,7 +514,7 @@ func TestApplyCommandRunner_ExecutionOrder(t *testing.T) { When(projectCommandBuilder.BuildApplyCommands(ctx, cmd)).ThenReturn(c.ProjectContexts, nil) for i := range c.ProjectContexts { - When(projectCommandRunner.Apply(c.ProjectContexts[i])).ThenReturn(c.ProjectResults[i]) + When(projectCommandRunner.Apply(c.ProjectContexts[i])).ThenReturn(c.ProjectCommandOutputs[i]) } applyCommandRunner.Run(ctx, cmd) diff --git a/server/events/command/project_context.go b/server/events/command/project_context.go index d6c5ffac72..a15a87d91b 100644 --- a/server/events/command/project_context.go +++ b/server/events/command/project_context.go @@ -23,6 +23,7 @@ const ( // be executed for a project. type ProjectContext struct { CommandName Name + SubCommand string // ApplyCmd is the command that users should run to apply this plan. If // this is an apply then this will be empty. ApplyCmd string diff --git a/server/events/command/project_result.go b/server/events/command/project_result.go index 4e54fe2090..c246393b1e 100644 --- a/server/events/command/project_result.go +++ b/server/events/command/project_result.go @@ -9,10 +9,17 @@ import ( // ProjectResult is the result of executing a plan/policy_check/apply for a specific project. type ProjectResult struct { - Command Name - SubCommand string - RepoRelDir string - Workspace string + ProjectCommandOutput + Command Name + SubCommand string + RepoRelDir string + Workspace string + ProjectName string + SilencePRComments []string +} + +// ProjectCommandOutput is the output of a plan/policy_check/apply for a specific project. +type ProjectCommandOutput struct { Error error Failure string PlanSuccess *models.PlanSuccess @@ -21,8 +28,6 @@ type ProjectResult struct { VersionSuccess string ImportSuccess *models.ImportSuccess StateRmSuccess *models.StateRmSuccess - ProjectName string - SilencePRComments []string } // CommitStatus returns the vcs commit status of this project result. diff --git a/server/events/command/project_result_test.go b/server/events/command/project_result_test.go index ca15511e40..0c28a4c87a 100644 --- a/server/events/command/project_result_test.go +++ b/server/events/command/project_result_test.go @@ -19,31 +19,41 @@ func TestProjectResult_IsSuccessful(t *testing.T) { }{ "plan success": { command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{}, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, true, }, "policy_check success": { command.ProjectResult{ - PolicyCheckResults: &models.PolicyCheckResults{}, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{}, + }, }, true, }, "apply success": { command.ProjectResult{ - ApplySuccess: "success", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, true, }, "failure": { command.ProjectResult{ - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, false, }, "error": { command.ProjectResult{ - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, false, }, @@ -64,29 +74,37 @@ func TestProjectResult_PlanStatus(t *testing.T) { { p: command.ProjectResult{ Command: command.Plan, - Error: errors.New("err"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("err"), + }, }, expStatus: models.ErroredPlanStatus, }, { p: command.ProjectResult{ Command: command.Plan, - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, expStatus: models.ErroredPlanStatus, }, { p: command.ProjectResult{ - Command: command.Plan, - PlanSuccess: &models.PlanSuccess{}, + Command: command.Plan, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, expStatus: models.PlannedPlanStatus, }, { p: command.ProjectResult{ Command: command.Plan, - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Infrastructure is up-to-date.", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Infrastructure is up-to-date.", + }, }, }, expStatus: models.PlannedNoChangesPlanStatus, @@ -94,49 +112,63 @@ func TestProjectResult_PlanStatus(t *testing.T) { { p: command.ProjectResult{ Command: command.Apply, - Error: errors.New("err"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("err"), + }, }, expStatus: models.ErroredApplyStatus, }, { p: command.ProjectResult{ Command: command.Apply, - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, expStatus: models.ErroredApplyStatus, }, { p: command.ProjectResult{ - Command: command.Apply, - ApplySuccess: "success", + Command: command.Apply, + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, expStatus: models.AppliedPlanStatus, }, { p: command.ProjectResult{ - Command: command.PolicyCheck, - PolicyCheckResults: &models.PolicyCheckResults{}, + Command: command.PolicyCheck, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{}, + }, }, expStatus: models.PassedPolicyCheckStatus, }, { p: command.ProjectResult{ Command: command.PolicyCheck, - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, expStatus: models.ErroredPolicyCheckStatus, }, { p: command.ProjectResult{ - Command: command.ApprovePolicies, - PolicyCheckResults: &models.PolicyCheckResults{}, + Command: command.ApprovePolicies, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{}, + }, }, expStatus: models.PassedPolicyCheckStatus, }, { p: command.ProjectResult{ Command: command.ApprovePolicies, - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, expStatus: models.ErroredPolicyCheckStatus, }, @@ -156,8 +188,9 @@ func TestPlanSuccess_Summary(t *testing.T) { }{ { p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: - destroy @@ -168,40 +201,46 @@ func TestPlanSuccess_Summary(t *testing.T) { Plan: 0 to add, 0 to change, 1 to destroy.`, + }, }, }, expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", }, { p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: No changes. Infrastructure is up-to-date.`, + }, }, }, expResult: "No changes. Infrastructure is up-to-date.", }, { p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` Note: Objects have changed outside of Terraform Terraform detected the following changes made outside of Terraform since the last "terraform apply": No changes. Your infrastructure matches the configuration.`, + }, }, }, expResult: "\n**Note: Objects have changed outside of Terraform**\nNo changes. Your infrastructure matches the configuration.", }, { p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` Note: Objects have changed outside of Terraform Terraform detected the following changes made outside of Terraform since the @@ -217,14 +256,17 @@ func TestPlanSuccess_Summary(t *testing.T) { Plan: 0 to add, 0 to change, 1 to destroy.`, + }, }, }, expResult: "\n**Note: Objects have changed outside of Terraform**\nPlan: 0 to add, 0 to change, 1 to destroy.", }, { p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: `No match, expect empty`, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: `No match, expect empty`, + }, }, }, expResult: "", diff --git a/server/events/command/result_test.go b/server/events/command/result_test.go index 9f6d586ac9..95839a5263 100644 --- a/server/events/command/result_test.go +++ b/server/events/command/result_test.go @@ -39,7 +39,9 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{}, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, }, }, @@ -49,7 +51,9 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - ApplySuccess: "success", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, }, }, @@ -59,7 +63,9 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - Error: errors.New("err"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("err"), + }, }, }, }, @@ -69,7 +75,9 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }, }, @@ -79,10 +87,14 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{}, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, { - ApplySuccess: "success", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, }, }, @@ -92,10 +104,14 @@ func TestCommandResult_HasErrors(t *testing.T) { cr: command.Result{ ProjectResults: []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{}, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, { - Failure: "failed", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failed", + }, }, }, }, diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index 46a2a01def..af3ffeefa6 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -814,7 +814,7 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { CommandName: command.Plan, }, }, nil) - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil) testdata.Pull.BaseRepo = testdata.GithubRepo ch.RunAutoplanCommand(testdata.GithubRepo, testdata.GithubRepo, testdata.Pull, testdata.User) @@ -839,7 +839,7 @@ func TestRunAutoplanCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Fal CommandName: command.Plan, }, }, nil) - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil) When(preWorkflowHooksCommandRunner.RunPreHooks(Any[*command.Context](), Any[*events.CommentCommand]())).ThenReturn(errors.New("err")) testdata.Pull.BaseRepo = testdata.GithubRepo @@ -896,7 +896,7 @@ func TestRunCommentCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Fals dbUpdater.Database = boltDB applyCommandRunner.Database = boltDB - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil) pull := &github.PullRequest{State: github.Ptr("open")} modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num} @@ -953,8 +953,7 @@ func TestRunGenericPlanCommand_DeletePlans(t *testing.T) { } When(projectCommandBuilder.BuildPlanCommands(Any[*command.Context](), Any[*events.CommentCommand]())). ThenReturn([]command.ProjectContext{projectCtx}, nil) - When(projectCommandRunner.Plan(projectCtx)).ThenReturn(command.ProjectResult{ - Command: command.Plan, + When(projectCommandRunner.Plan(projectCtx)).ThenReturn(command.ProjectCommandOutput{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -983,7 +982,7 @@ func TestRunSpecificPlanCommandDoesnt_DeletePlans(t *testing.T) { autoMerger.GlobalAutomerge = true defer func() { autoMerger.GlobalAutomerge = false }() - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil) testdata.Pull.BaseRepo = testdata.GithubRepo ch.RunCommentCommand(testdata.GithubRepo, nil, nil, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.Plan, ProjectName: "default"}) @@ -1022,14 +1021,14 @@ func TestRunAutoplanCommandWithError_DeletePlans(t *testing.T) { // The first call, we return a successful result. callCount++ return ReturnValues{ - command.ProjectResult{ + command.ProjectCommandOutput{ PlanSuccess: &models.PlanSuccess{}, }, } } // The second call, we return a failed result. return ReturnValues{ - command.ProjectResult{ + command.ProjectCommandOutput{ Error: errors.New("err"), }, } @@ -1061,7 +1060,7 @@ func TestRunGenericPlanCommand_DiscardApprovals(t *testing.T) { autoMerger.GlobalAutomerge = true defer func() { autoMerger.GlobalAutomerge = false }() - When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(Any[models.Repo](), Any[models.PullRequest]())).ThenReturn(tmp, nil) pull := &github.PullRequest{State: github.Ptr("open")} modelPull := models.PullRequest{BaseRepo: testdata.GithubRepo, State: models.OpenPullState, Num: testdata.Pull.Num} @@ -1102,8 +1101,10 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { _, _ = boltDB.UpdatePullWithResults(modelPull, []command.ProjectResult{ { - Command: command.PolicyCheck, - Error: fmt.Errorf("failing policy"), + Command: command.PolicyCheck, + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: fmt.Errorf("failing policy"), + }, ProjectName: "default", Workspace: "default", RepoRelDir: ".", @@ -1175,9 +1176,11 @@ func TestRunApply_DiscardedProjects(t *testing.T) { Command: command.Plan, RepoRelDir: ".", Workspace: "default", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "tf-output", - LockURL: "lock-url", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "tf-output", + LockURL: "lock-url", + }, }, }, }) diff --git a/server/events/commit_status_updater.go b/server/events/commit_status_updater.go index a05b7ef808..da0ac55e90 100644 --- a/server/events/commit_status_updater.go +++ b/server/events/commit_status_updater.go @@ -82,7 +82,7 @@ func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(logger logging.SimpleLo return d.Client.UpdateStatus(logger, repo, pull, status, src, fmt.Sprintf("%d/%d projects %s successfully.", numSuccess, numTotal, cmdVerb), "") } -func (d *DefaultCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, result *command.ProjectResult) error { +func (d *DefaultCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, result *command.ProjectCommandOutput) error { projectID := ctx.ProjectName if projectID == "" { projectID = fmt.Sprintf("%s/%s", ctx.RepoRelDir, ctx.Workspace) diff --git a/server/events/commit_status_updater_test.go b/server/events/commit_status_updater_test.go index 1fe059f203..a9a12e7ef7 100644 --- a/server/events/commit_status_updater_test.go +++ b/server/events/commit_status_updater_test.go @@ -193,7 +193,7 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { cases := []struct { status models.CommitStatus cmd command.Name - result *command.ProjectResult + result *command.ProjectCommandOutput expDescrip string }{ { @@ -209,7 +209,7 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { { status: models.SuccessCommitStatus, cmd: command.Plan, - result: &command.ProjectResult{ + result: &command.ProjectCommandOutput{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: "aaa\nNote: Objects have changed outside of Terraform\nbbb\nPlan: 1 to add, 2 to change, 3 to destroy.\nbbb", }, @@ -229,7 +229,7 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { { status: models.SuccessCommitStatus, cmd: command.Apply, - result: &command.ProjectResult{ + result: &command.ProjectCommandOutput{ ApplySuccess: "success", }, expDescrip: "Apply succeeded.", diff --git a/server/events/instrumented_project_command_runner.go b/server/events/instrumented_project_command_runner.go index a14efbe6df..468ed79dc4 100644 --- a/server/events/instrumented_project_command_runner.go +++ b/server/events/instrumented_project_command_runner.go @@ -37,31 +37,31 @@ func NewInstrumentedProjectCommandRunner(scope tally.Scope, projectCommandRunner } } -func (p *InstrumentedProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.Plan, p.scope) } -func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.PolicyCheck, p.scope) } -func (p *InstrumentedProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.Apply, p.scope) } -func (p *InstrumentedProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.ApprovePolicies, p.scope) } -func (p *InstrumentedProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.Import, p.scope) } -func (p *InstrumentedProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectResult { +func (p *InstrumentedProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectCommandOutput { return RunAndEmitStats(ctx, p.projectCommandRunner.StateRm, p.scope) } -func RunAndEmitStats(ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult, scope tally.Scope) command.ProjectResult { +func RunAndEmitStats(ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectCommandOutput, scope tally.Scope) command.ProjectCommandOutput { commandName := ctx.CommandName.String() // ensures we are differentiating between project level command and overall command scope = ctx.SetProjectScopeTags(scope).SubScope(commandName) diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 2fb90c256b..012396bd72 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -244,11 +244,13 @@ func TestRenderProjectResults(t *testing.T) { "", []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -289,12 +291,14 @@ $$$ "", []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", - MergedAgain: true, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + MergedAgain: true, + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -336,11 +340,13 @@ $$$ "", []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -382,28 +388,30 @@ $$$ "", []command.ProjectResult{ { - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - // strings.Repeat require to get wrapped result - PolicyOutput: `FAIL - - main - WARNING: Null Resource creation is prohibited. + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + // strings.Repeat require to get wrapped result + PolicyOutput: `FAIL - - main - WARNING: Null Resource creation is prohibited. 2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions`, - Passed: false, - ReqApprovals: 1, - }, - { - PolicySetName: "policy2", - // strings.Repeat require to get wrapped result - PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", - Passed: true, - ReqApprovals: 1, + Passed: false, + ReqApprovals: 1, + }, + { + PolicySetName: "policy2", + // strings.Repeat require to get wrapped result + PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", + Passed: true, + ReqApprovals: 1, + }, }, + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", }, - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", }, Workspace: "workspace", RepoRelDir: "path", @@ -459,21 +467,23 @@ $$$ "", []command.ProjectResult{ { - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - // strings.Repeat require to get wrapped result - PolicyOutput: strings.Repeat("line\n", 13) + `FAIL - - main - WARNING: Null Resource creation is prohibited. + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + // strings.Repeat require to get wrapped result + PolicyOutput: strings.Repeat("line\n", 13) + `FAIL - - main - WARNING: Null Resource creation is prohibited. 2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions`, - Passed: false, - ReqApprovals: 1, + Passed: false, + ReqApprovals: 1, + }, }, + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", }, - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", }, Workspace: "workspace", RepoRelDir: "path", @@ -543,9 +553,11 @@ $$$ "", []command.ProjectResult{ { - ImportSuccess: &models.ImportSuccess{ - Output: "import-output", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + ImportSuccess: &models.ImportSuccess{ + Output: "import-output", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -574,9 +586,11 @@ $$$ "rm", []command.ProjectResult{ { - StateRmSuccess: &models.StateRmSuccess{ - Output: "state-rm-output", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + StateRmSuccess: &models.StateRmSuccess{ + Output: "state-rm-output", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -605,9 +619,11 @@ $$$ "", []command.ProjectResult{ { - ApplySuccess: "success", - Workspace: "workspace", - RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, + Workspace: "workspace", + RepoRelDir: "path", }, }, models.Github, @@ -625,10 +641,12 @@ $$$ "", []command.ProjectResult{ { - ApplySuccess: "success", - Workspace: "workspace", - RepoRelDir: "path", - ProjectName: "projectname", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, + Workspace: "workspace", + RepoRelDir: "path", + ProjectName: "projectname", }, }, models.Github, @@ -648,22 +666,26 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output2", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output2", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -729,33 +751,37 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, }, + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", }, - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, - }, - }, LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, + }, LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -819,15 +845,19 @@ $$$ "", []command.ProjectResult{ { - RepoRelDir: "path", - Workspace: "workspace", - ProjectName: "projectname", - ApplySuccess: "success", + RepoRelDir: "path", + Workspace: "workspace", + ProjectName: "projectname", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { - RepoRelDir: "path2", - Workspace: "workspace", - ApplySuccess: "success2", + RepoRelDir: "path2", + Workspace: "workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success2", + }, }, }, models.Github, @@ -861,7 +891,9 @@ $$$ "", []command.ProjectResult{ { - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, RepoRelDir: "path", Workspace: "workspace", }, @@ -884,7 +916,9 @@ $$$ { RepoRelDir: "path", Workspace: "workspace", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }, models.Github, @@ -902,23 +936,29 @@ Ran Plan for dir: $path$ workspace: $workspace$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -979,40 +1019,46 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, - }, - }, LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, + }, LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 2 passed, 0 warnings, 2 failures, 0 exceptions", - Passed: false, - ReqApprovals: 1, - }, - }, LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 2 passed, 0 warnings, 2 failures, 0 exceptions", + Passed: false, + ReqApprovals: 1, + }, + }, LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -1092,19 +1138,25 @@ $$$ "", []command.ProjectResult{ { - Workspace: "workspace", - RepoRelDir: "path", - ApplySuccess: "success", + Workspace: "workspace", + RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -1144,19 +1196,25 @@ $$$ "", []command.ProjectResult{ { - Workspace: "workspace", - RepoRelDir: "path", - ApplySuccess: "success", + Workspace: "workspace", + RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -1258,26 +1316,28 @@ func TestRenderProjectResultsWithQuietPolicyChecks(t *testing.T) { "", []command.ProjectResult{ { - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: `FAIL - - main - WARNING: Null Resource creation is prohibited. + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: `FAIL - - main - WARNING: Null Resource creation is prohibited. 2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions`, - Passed: false, - ReqApprovals: 1, - }, - { - PolicySetName: "policy2", - PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", - Passed: true, - ReqApprovals: 1, + Passed: false, + ReqApprovals: 1, + }, + { + PolicySetName: "policy2", + PolicyOutput: "2 tests, 2 passed, 0 warnings, 0 failure, 0 exceptions", + Passed: true, + ReqApprovals: 1, + }, }, + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", }, - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", }, Workspace: "workspace", RepoRelDir: "path", @@ -1333,21 +1393,23 @@ $$$ "", []command.ProjectResult{ { - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - // strings.Repeat require to get wrapped result - PolicyOutput: strings.Repeat("line\n", 13) + `FAIL - - main - WARNING: Null Resource creation is prohibited. + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + // strings.Repeat require to get wrapped result + PolicyOutput: strings.Repeat("line\n", 13) + `FAIL - - main - WARNING: Null Resource creation is prohibited. 2 tests, 1 passed, 0 warnings, 1 failure, 0 exceptions`, - Passed: false, - ReqApprovals: 1, + Passed: false, + ReqApprovals: 1, + }, }, + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", }, - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", }, Workspace: "workspace", RepoRelDir: "path", @@ -1419,33 +1481,37 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, }, + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", }, - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, - }, - }, LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, + }, LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -1475,40 +1541,46 @@ Ran Policy Check for 2 projects: { Workspace: "workspace", RepoRelDir: "path", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, - }, - }, LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, + }, LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 2 passed, 0 warnings, 2 failures, 0 exceptions", - Passed: false, - ReqApprovals: 1, - }, - }, LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 2 passed, 0 warnings, 2 failures, 0 exceptions", + Passed: false, + ReqApprovals: 1, + }, + }, LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -1631,11 +1703,13 @@ func TestRenderProjectResultsDisableApplyAll(t *testing.T) { command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -1665,11 +1739,13 @@ $$$ command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -1702,22 +1778,26 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output2", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output2", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -1831,11 +1911,13 @@ func TestRenderProjectResultsDisableApply(t *testing.T) { command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -1861,11 +1943,13 @@ $$$ command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -1894,22 +1978,26 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output2", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output2", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -2042,16 +2130,18 @@ func TestRenderCustomPolicyCheckTemplate_DisableApplyAll(t *testing.T) { { Workspace: "workspace", RepoRelDir: "path", - PolicyCheckResults: &models.PolicyCheckResults{ - PolicySetResults: []models.PolicySetResult{ - { - PolicySetName: "policy1", - PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", - Passed: true, - }, - }, LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PolicyCheckResults: &models.PolicyCheckResults{ + PolicySetResults: []models.PolicySetResult{ + { + PolicySetName: "policy1", + PolicyOutput: "4 tests, 4 passed, 0 warnings, 0 failures, 0 exceptions", + Passed: true, + }, + }, LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, }, @@ -2116,7 +2206,9 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Error: errors.New(strings.Repeat("line\n", 13)), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New(strings.Repeat("line\n", 13)), + }, }, }, } @@ -2226,7 +2318,9 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { { RepoRelDir: ".", Workspace: "default", - Error: errors.New(c.Output), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New(c.Output), + }, }, }, } @@ -2374,18 +2468,22 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { pr = command.ProjectResult{ RepoRelDir: ".", Workspace: "default", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: c.Output, - LockURL: "lock-url", - RePlanCmd: "replancmd", - ApplyCmd: "applycmd", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: c.Output, + LockURL: "lock-url", + RePlanCmd: "replancmd", + ApplyCmd: "applycmd", + }, }, } case command.Apply: pr = command.ProjectResult{ - RepoRelDir: ".", - Workspace: "default", - ApplySuccess: c.Output, + RepoRelDir: ".", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: c.Output, + }, } } res := command.Result{ @@ -2522,14 +2620,18 @@ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { res := command.Result{ ProjectResults: []command.ProjectResult{ { - RepoRelDir: ".", - Workspace: "staging", - ApplySuccess: tfOut, + RepoRelDir: ".", + Workspace: "staging", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: tfOut, + }, }, { - RepoRelDir: ".", - Workspace: "production", - ApplySuccess: tfOut, + RepoRelDir: ".", + Workspace: "production", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: tfOut, + }, }, }, } @@ -2604,21 +2706,25 @@ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { { RepoRelDir: ".", Workspace: "staging", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: tfOut, - LockURL: "staging-lock-url", - ApplyCmd: "staging-apply-cmd", - RePlanCmd: "staging-replan-cmd", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: tfOut, + LockURL: "staging-lock-url", + ApplyCmd: "staging-apply-cmd", + RePlanCmd: "staging-replan-cmd", + }, }, }, { RepoRelDir: ".", Workspace: "production", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: tfOut, - LockURL: "production-lock-url", - ApplyCmd: "production-apply-cmd", - RePlanCmd: "production-replan-cmd", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: tfOut, + LockURL: "production-lock-url", + ApplyCmd: "production-apply-cmd", + RePlanCmd: "production-replan-cmd", + }, }, }, }, @@ -2704,7 +2810,9 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { { RepoRelDir: ".", Workspace: "staging", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }, PlansDeleted: true, @@ -2721,12 +2829,16 @@ Ran Plan for dir: $.$ workspace: $staging$ { RepoRelDir: ".", Workspace: "staging", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { RepoRelDir: ".", Workspace: "production", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }, PlansDeleted: true, @@ -2757,16 +2869,20 @@ Ran Plan for 2 projects: { RepoRelDir: ".", Workspace: "staging", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { RepoRelDir: ".", Workspace: "production", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "tf out", - LockURL: "lock-url", - RePlanCmd: "re-plan cmd", - ApplyCmd: "apply cmd", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "tf out", + LockURL: "lock-url", + RePlanCmd: "re-plan cmd", + ApplyCmd: "apply cmd", + }, }, }, }, @@ -2856,11 +2972,13 @@ func TestRenderProjectResultsWithRepoLockingDisabled(t *testing.T) { command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -2899,12 +3017,14 @@ $$$ command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", - MergedAgain: true, + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + MergedAgain: true, + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -2944,11 +3064,13 @@ $$$ command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -2988,9 +3110,11 @@ $$$ command.Apply, []command.ProjectResult{ { - ApplySuccess: "success", - Workspace: "workspace", - RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, + Workspace: "workspace", + RepoRelDir: "path", }, }, models.Github, @@ -3007,10 +3131,12 @@ $$$ command.Apply, []command.ProjectResult{ { - ApplySuccess: "success", - Workspace: "workspace", - RepoRelDir: "path", - ProjectName: "projectname", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, + Workspace: "workspace", + RepoRelDir: "path", + ProjectName: "projectname", }, }, models.Github, @@ -3029,22 +3155,26 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output2", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output2", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -3105,15 +3235,19 @@ $$$ command.Apply, []command.ProjectResult{ { - RepoRelDir: "path", - Workspace: "workspace", - ProjectName: "projectname", - ApplySuccess: "success", + RepoRelDir: "path", + Workspace: "workspace", + ProjectName: "projectname", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { - RepoRelDir: "path2", - Workspace: "workspace", - ApplySuccess: "success2", + RepoRelDir: "path2", + Workspace: "workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success2", + }, }, }, models.Github, @@ -3146,7 +3280,9 @@ $$$ command.Plan, []command.ProjectResult{ { - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, RepoRelDir: "path", Workspace: "workspace", }, @@ -3168,7 +3304,9 @@ $$$ { RepoRelDir: "path", Workspace: "workspace", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, }, models.Github, @@ -3185,23 +3323,29 @@ Ran Plan for dir: $path$ workspace: $workspace$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -3258,19 +3402,25 @@ $$$ command.Apply, []command.ProjectResult{ { - Workspace: "workspace", - RepoRelDir: "path", - ApplySuccess: "success", + Workspace: "workspace", + RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -3309,19 +3459,25 @@ $$$ command.Apply, []command.ProjectResult{ { - Workspace: "workspace", - RepoRelDir: "path", - ApplySuccess: "success", + Workspace: "workspace", + RepoRelDir: "path", + ProjectCommandOutput: command.ProjectCommandOutput{ + ApplySuccess: "success", + }, }, { Workspace: "workspace", RepoRelDir: "path2", - Failure: "failure", + ProjectCommandOutput: command.ProjectCommandOutput{ + Failure: "failure", + }, }, { Workspace: "workspace", RepoRelDir: "path3", - Error: errors.New("error"), + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: errors.New("error"), + }, }, }, models.Github, @@ -3422,22 +3578,26 @@ func TestRenderProjectResultsWithGitLab(t *testing.T) { { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output2", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output2", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, }, @@ -3742,11 +3902,13 @@ var cases = []struct { command.Plan, []command.ProjectResult{ { - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: tfOutput, - LockURL: "lock-url", - RePlanCmd: "atlantis plan -d path -w workspace", - ApplyCmd: "atlantis apply -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: tfOutput, + LockURL: "lock-url", + RePlanCmd: "atlantis plan -d path -w workspace", + ApplyCmd: "atlantis apply -d path -w workspace", + }, }, Workspace: "workspace", RepoRelDir: "path", @@ -4076,33 +4238,39 @@ func TestRenderProjectResultsHideUnchangedPlans(t *testing.T) { { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Infrastructure is up-to-date.", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Infrastructure is up-to-date.", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname2", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "terraform-output3", - LockURL: "lock-url3", - ApplyCmd: "atlantis apply -d path3 -w workspace", - RePlanCmd: "atlantis plan -d path3 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "terraform-output3", + LockURL: "lock-url3", + ApplyCmd: "atlantis apply -d path3 -w workspace", + RePlanCmd: "atlantis plan -d path3 -w workspace", + }, }, }, }, @@ -4169,33 +4337,39 @@ $$$ { Workspace: "workspace", RepoRelDir: "path", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Infrastructure is up-to-date.", - LockURL: "lock-url", - ApplyCmd: "atlantis apply -d path -w workspace", - RePlanCmd: "atlantis plan -d path -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Infrastructure is up-to-date.", + LockURL: "lock-url", + ApplyCmd: "atlantis apply -d path -w workspace", + RePlanCmd: "atlantis plan -d path -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path2", ProjectName: "projectname", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Infrastructure is up-to-date.", - LockURL: "lock-url2", - ApplyCmd: "atlantis apply -d path2 -w workspace", - RePlanCmd: "atlantis plan -d path2 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Infrastructure is up-to-date.", + LockURL: "lock-url2", + ApplyCmd: "atlantis apply -d path2 -w workspace", + RePlanCmd: "atlantis plan -d path2 -w workspace", + }, }, }, { Workspace: "workspace", RepoRelDir: "path3", ProjectName: "projectname2", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Infrastructure is up-to-date.", - LockURL: "lock-url3", - ApplyCmd: "atlantis apply -d path3 -w workspace", - RePlanCmd: "atlantis plan -d path3 -w workspace", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Infrastructure is up-to-date.", + LockURL: "lock-url3", + ApplyCmd: "atlantis apply -d path3 -w workspace", + RePlanCmd: "atlantis plan -d path3 -w workspace", + }, }, }, }, diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index 6455c4a201..3d1d29f251 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -26,7 +26,7 @@ func NewMockJobURLSetter(options ...pegomock.Option) *MockJobURLSetter { func (mock *MockJobURLSetter) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobURLSetter) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectResult) error { +func (mock *MockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectCommandOutput) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobURLSetter().") } @@ -78,7 +78,7 @@ type VerifierMockJobURLSetter struct { timeout time.Duration } -func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectResult) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { +func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectCommandOutput) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { _params := []pegomock.Param{ctx, cmdName, status, res} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", _params, verifier.timeout) return &MockJobURLSetter_SetJobURLWithStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -89,12 +89,12 @@ type MockJobURLSetter_SetJobURLWithStatus_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, *command.ProjectResult) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, *command.ProjectCommandOutput) { ctx, cmdName, status, res := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], res[len(res)-1] } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []*command.ProjectResult) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []*command.ProjectCommandOutput) { _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(_params) > 0 { if len(_params) > 0 { @@ -116,9 +116,9 @@ func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapture } } if len(_params) > 3 { - _param3 = make([]*command.ProjectResult, len(c.methodInvocations)) + _param3 = make([]*command.ProjectCommandOutput, len(c.methodInvocations)) for u, param := range _params[3] { - _param3[u] = param.(*command.ProjectResult) + _param3[u] = param.(*command.ProjectCommandOutput) } } } diff --git a/server/events/mocks/mock_project_command_runner.go b/server/events/mocks/mock_project_command_runner.go index dc30989b45..5a9cf3cd65 100644 --- a/server/events/mocks/mock_project_command_runner.go +++ b/server/events/mocks/mock_project_command_runner.go @@ -25,106 +25,106 @@ func NewMockProjectCommandRunner(options ...pegomock.Option) *MockProjectCommand func (mock *MockProjectCommandRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("Import", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("Import", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("StateRm", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("StateRm", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 } -func (mock *MockProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectResult { +func (mock *MockProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectCommandOutput { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } _params := []pegomock.Param{ctx} - _result := pegomock.GetGenericMockFrom(mock).Invoke("Version", _params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) - var _ret0 command.ProjectResult + _result := pegomock.GetGenericMockFrom(mock).Invoke("Version", _params, []reflect.Type{reflect.TypeOf((*command.ProjectCommandOutput)(nil)).Elem()}) + var _ret0 command.ProjectCommandOutput if len(_result) != 0 { if _result[0] != nil { - _ret0 = _result[0].(command.ProjectResult) + _ret0 = _result[0].(command.ProjectCommandOutput) } } return _ret0 diff --git a/server/events/plan_command_runner_test.go b/server/events/plan_command_runner_test.go index 659b4bdf96..6491e2daf2 100644 --- a/server/events/plan_command_runner_test.go +++ b/server/events/plan_command_runner_test.go @@ -112,10 +112,12 @@ func TestPlanCommandRunner_IsSilenced(t *testing.T) { if c.PrevPlanStored { _, err = db.UpdatePullWithResults(modelPull, []command.ProjectResult{ { - Command: command.Plan, - RepoRelDir: "prevdir", - Workspace: "default", - PlanSuccess: &models.PlanSuccess{}, + Command: command.Plan, + RepoRelDir: "prevdir", + Workspace: "default", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{}, + }, }, }) Ok(t, err) @@ -127,6 +129,7 @@ func TestPlanCommandRunner_IsSilenced(t *testing.T) { } return ReturnValues{[]command.ProjectContext{}, nil} }) + When(projectCommandRunner.Plan(Any[command.ProjectContext]())).ThenReturn(command.ProjectCommandOutput{PlanSuccess: &models.PlanSuccess{}}) planCommandRunner.Run(ctx, cmd) @@ -167,12 +170,12 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { RegisterMockTestingT(t) cases := []struct { - Description string - ProjectContexts []command.ProjectContext - ProjectResults []command.ProjectResult - RunnerInvokeMatch []*EqMatcher - PrevPlanStored bool - PlanFailed bool + Description string + ProjectContexts []command.ProjectContext + ProjectCommandOutputs []command.ProjectCommandOutput + RunnerInvokeMatch []*EqMatcher + PrevPlanStored bool + PlanFailed bool }{ { Description: "When first plan fails, the second don't run", @@ -194,16 +197,14 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, }, RunnerInvokeMatch: []*EqMatcher{ @@ -230,13 +231,12 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, + { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{}, }, }, @@ -266,13 +266,12 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, + { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{}, }, }, @@ -311,25 +310,21 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -372,25 +367,24 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Fourth", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, + { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, + { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, + { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -420,13 +414,11 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { AbortOnExecutionOrderFail: true, }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -452,15 +444,13 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Second", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, }, { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -486,13 +476,11 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { ProjectName: "Second", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutputs: []command.ProjectCommandOutput{ { - Command: command.Plan, - Error: errors.New("shabang"), + Error: errors.New("shabang"), }, { - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "true", }, @@ -547,7 +535,7 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) { // return ReturnValues{[]command.ProjectContext{{CommandName: command.Plan}}, nil} // }) for i := range c.ProjectContexts { - When(projectCommandRunner.Plan(c.ProjectContexts[i])).ThenReturn(c.ProjectResults[i]) + When(projectCommandRunner.Plan(c.ProjectContexts[i])).ThenReturn(c.ProjectCommandOutputs[i]) } planCommandRunner.Run(ctx, cmd) @@ -572,7 +560,7 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { cases := []struct { Description string ProjectContexts []command.ProjectContext - ProjectResults []command.ProjectResult + ProjectCommandOutput []command.ProjectCommandOutput PrevPlanStored bool // stores a previous "No changes" plan in the database DoNotUpdateApply bool // certain circumtances we want to skip the call to update apply ExpVCSApplyStatusTotal int @@ -586,10 +574,8 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 0 to add, 0 to change, 1 to destroy.", }, @@ -605,10 +591,8 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, @@ -625,10 +609,8 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 0 to add, 0 to change, 1 to destroy.", }, @@ -645,10 +627,8 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, @@ -667,11 +647,8 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { Workspace: "default", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "prevdir", - Workspace: "default", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 0 to add, 0 to change, 1 to destroy.", }, @@ -693,18 +670,13 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "prevdir", - Workspace: "default", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 0 to add, 0 to change, 1 to destroy.", }, }, { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, @@ -726,18 +698,13 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { RepoRelDir: "mydir", }, }, - ProjectResults: []command.ProjectResult{ + ProjectCommandOutput: []command.ProjectCommandOutput{ { - RepoRelDir: "prevdir", - Workspace: "default", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, }, { - RepoRelDir: "mydir", - Command: command.Plan, PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, @@ -783,8 +750,10 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { Command: command.Plan, RepoRelDir: "prevdir", Workspace: "default", - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: "No changes. Your infrastructure matches the configuration.", + ProjectCommandOutput: command.ProjectCommandOutput{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: "No changes. Your infrastructure matches the configuration.", + }, }, }, }) @@ -794,7 +763,7 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) { When(projectCommandBuilder.BuildPlanCommands(ctx, cmd)).ThenReturn(c.ProjectContexts, nil) for i := range c.ProjectContexts { - When(projectCommandRunner.Plan(c.ProjectContexts[i])).ThenReturn(c.ProjectResults[i]) + When(projectCommandRunner.Plan(c.ProjectContexts[i])).ThenReturn(c.ProjectCommandOutput[i]) } planCommandRunner.Run(ctx, cmd) @@ -901,7 +870,7 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description string VCSType models.VCSHostType PendingApplyFlag bool - ProjectResults []command.ProjectResult + ProjectResults []command.ProjectCommandOutput ExpApplyStatus models.CommitStatus ExpVCSApplyStatusTotal int ExpVCSApplyStatusSucc int @@ -911,10 +880,8 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description: "GitLab with flag enabled and unapplied plans should set pending status", VCSType: models.Gitlab, PendingApplyFlag: true, - ProjectResults: []command.ProjectResult{ + ProjectResults: []command.ProjectCommandOutput{ { - Command: command.Plan, - RepoRelDir: "mydir", PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 1 to add, 0 to change, 0 to destroy.", }, @@ -929,10 +896,8 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description: "GitLab with flag disabled and unapplied plans should NOT update apply status", VCSType: models.Gitlab, PendingApplyFlag: false, - ProjectResults: []command.ProjectResult{ + ProjectResults: []command.ProjectCommandOutput{ { - Command: command.Plan, - RepoRelDir: "mydir", PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 1 to add, 0 to change, 0 to destroy.", }, @@ -944,10 +909,8 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description: "GitHub with flag enabled should NOT update apply status (default behavior)", VCSType: models.Github, PendingApplyFlag: true, - ProjectResults: []command.ProjectResult{ + ProjectResults: []command.ProjectCommandOutput{ { - Command: command.Plan, - RepoRelDir: "mydir", PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 1 to add, 0 to change, 0 to destroy.", }, @@ -959,10 +922,8 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description: "GitLab with all plans applied should set success status", VCSType: models.Gitlab, PendingApplyFlag: true, - ProjectResults: []command.ProjectResult{ + ProjectResults: []command.ProjectCommandOutput{ { - Command: command.Plan, - RepoRelDir: "mydir", PlanSuccess: &models.PlanSuccess{ TerraformOutput: "No changes. Infrastructure is up-to-date.", }, @@ -977,10 +938,8 @@ func TestPlanCommandRunner_PendingApplyStatus(t *testing.T) { Description: "Bitbucket with flag enabled should NOT update apply status", VCSType: models.BitbucketCloud, PendingApplyFlag: true, - ProjectResults: []command.ProjectResult{ + ProjectResults: []command.ProjectCommandOutput{ { - Command: command.Plan, - RepoRelDir: "mydir", PlanSuccess: &models.PlanSuccess{ TerraformOutput: "Plan: 1 to add, 0 to change, 0 to destroy.", }, diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index b0ff88f6e1..255b76d773 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -134,6 +134,7 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( projectCmdContext := newProjectCommandContext( ctx, cmdName, + subName, cb.CommentBuilder.BuildApplyComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, prjCfg.AutoMergeDisabled, prjCfg.AutoMergeMethod), cb.CommentBuilder.BuildApprovePoliciesComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name), cb.CommentBuilder.BuildPlanComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, commentFlags), @@ -207,6 +208,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( projectCmds = append(projectCmds, newProjectCommandContext( ctx, command.PolicyCheck, + "", cb.CommentBuilder.BuildApplyComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, prjCfg.AutoMergeDisabled, prjCfg.AutoMergeMethod), cb.CommentBuilder.BuildApprovePoliciesComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name), cb.CommentBuilder.BuildPlanComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, commentFlags), @@ -233,6 +235,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( // ProjectCommandContext. func newProjectCommandContext(ctx *command.Context, cmd command.Name, + subCommand string, applyCmd string, approvePoliciesCmd string, planCmd string, @@ -274,6 +277,7 @@ func newProjectCommandContext(ctx *command.Context, return command.ProjectContext{ CommandName: cmd, + SubCommand: subCommand, ApplyCmd: applyCmd, ApprovePoliciesCmd: approvePoliciesCmd, BaseRepo: ctx.Pull.BaseRepo, diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index 27aef1ce8c..bac02945a8 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -12,7 +12,24 @@ import ( "github.com/runatlantis/atlantis/server/events/command" ) -type prjCmdRunnerFunc func(ctx command.ProjectContext) command.ProjectResult +type prjCmdRunnerFunc func(ctx command.ProjectContext) command.ProjectCommandOutput + +func RunOneProjectCmd( + runnerFunc prjCmdRunnerFunc, + cmd command.ProjectContext, +) command.ProjectResult { + projectCommandOutput := runnerFunc(cmd) + + return command.ProjectResult{ + ProjectCommandOutput: projectCommandOutput, + Command: cmd.CommandName, + SubCommand: cmd.SubCommand, + RepoRelDir: cmd.RepoRelDir, + Workspace: cmd.Workspace, + ProjectName: cmd.ProjectName, + SilencePRComments: cmd.SilencePRComments, + } +} func runProjectCmdsParallel( cmds []command.ProjectContext, @@ -29,7 +46,7 @@ func runProjectCmdsParallel( execute = func() { defer wg.Done() - res := runnerFunc(pCmd) + res := RunOneProjectCmd(runnerFunc, pCmd) mux.Lock() results = append(results, res) mux.Unlock() @@ -48,7 +65,7 @@ func runProjectCmds( ) command.Result { var results []command.ProjectResult for _, pCmd := range cmds { - res := runnerFunc(pCmd) + res := RunOneProjectCmd(runnerFunc, pCmd) results = append(results, res) } @@ -100,7 +117,7 @@ func runProjectCmdsWithCancellationTracker( cancellationTracker CancellationTracker, parallelPoolSize int, isParallel bool, - runnerFunc func(command.ProjectContext) command.ProjectResult, + runnerFunc prjCmdRunnerFunc, ) command.Result { if isParallel { ctx.Log.Info("Running commands in parallel") @@ -155,8 +172,10 @@ func createCancelledResults(remainingGroups [][]command.ProjectContext) []comman for _, group := range remainingGroups { for _, cmd := range group { cancelledResults = append(cancelledResults, command.ProjectResult{ - Command: cmd.CommandName, - Error: fmt.Errorf("operation cancelled"), + Command: cmd.CommandName, + ProjectCommandOutput: command.ProjectCommandOutput{ + Error: fmt.Errorf("operation cancelled"), + }, RepoRelDir: cmd.RepoRelDir, Workspace: cmd.Workspace, ProjectName: cmd.ProjectName, @@ -168,7 +187,7 @@ func createCancelledResults(remainingGroups [][]command.ProjectContext) []comman func runGroup( group []command.ProjectContext, - runnerFunc func(command.ProjectContext) command.ProjectResult, + runnerFunc prjCmdRunnerFunc, isParallel bool, parallelPoolSize int, ) command.Result { diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index a773741ba5..99f68e4f7e 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -116,37 +116,37 @@ type WebhooksSender interface { type ProjectPlanCommandRunner interface { // Plan runs terraform plan for the project described by ctx. - Plan(ctx command.ProjectContext) command.ProjectResult + Plan(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectApplyCommandRunner interface { // Apply runs terraform apply for the project described by ctx. - Apply(ctx command.ProjectContext) command.ProjectResult + Apply(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectPolicyCheckCommandRunner interface { // PolicyCheck runs OPA defined policies for the project described by ctx. - PolicyCheck(ctx command.ProjectContext) command.ProjectResult + PolicyCheck(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectApprovePoliciesCommandRunner interface { // Approves any failing OPA policies. - ApprovePolicies(ctx command.ProjectContext) command.ProjectResult + ApprovePolicies(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectVersionCommandRunner interface { // Version runs terraform version for the project described by ctx. - Version(ctx command.ProjectContext) command.ProjectResult + Version(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectImportCommandRunner interface { // Import runs terraform import for the project described by ctx. - Import(ctx command.ProjectContext) command.ProjectResult + Import(ctx command.ProjectContext) command.ProjectCommandOutput } type ProjectStateCommandRunner interface { // StateRm runs terraform state rm for the project described by ctx. - StateRm(ctx command.ProjectContext) command.ProjectResult + StateRm(ctx command.ProjectContext) command.ProjectCommandOutput } // ProjectCommandRunner runs project commands. A project command is a command @@ -166,7 +166,7 @@ type ProjectCommandRunner interface { type JobURLSetter interface { // SetJobURLWithStatus sets the commit status for the project represented by // ctx and updates the status with and url to a job. - SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectResult) error + SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, res *command.ProjectCommandOutput) error } //go:generate pegomock generate --package mocks -o mocks/mock_job_message_sender.go JobMessageSender @@ -183,19 +183,19 @@ type ProjectOutputWrapper struct { JobURLSetter JobURLSetter } -func (p *ProjectOutputWrapper) Plan(ctx command.ProjectContext) command.ProjectResult { +func (p *ProjectOutputWrapper) Plan(ctx command.ProjectContext) command.ProjectCommandOutput { result := p.updateProjectPRStatus(command.Plan, ctx, p.ProjectCommandRunner.Plan) p.JobMessageSender.Send(ctx, "", OperationComplete) return result } -func (p *ProjectOutputWrapper) Apply(ctx command.ProjectContext) command.ProjectResult { +func (p *ProjectOutputWrapper) Apply(ctx command.ProjectContext) command.ProjectCommandOutput { result := p.updateProjectPRStatus(command.Apply, ctx, p.ProjectCommandRunner.Apply) p.JobMessageSender.Send(ctx, "", OperationComplete) return result } -func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult) command.ProjectResult { +func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectCommandOutput) command.ProjectCommandOutput { // Create a PR status to track project's plan status. The status will // include a link to view the progress of atlantis plan command in real // time @@ -248,101 +248,70 @@ type DefaultProjectCommandRunner struct { } // Plan runs terraform plan for the project described by ctx. -func (p *DefaultProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectCommandOutput { planSuccess, failure, err := p.doPlan(ctx) - return command.ProjectResult{ - Command: command.Plan, - PlanSuccess: planSuccess, - Error: err, - Failure: failure, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, - SilencePRComments: ctx.SilencePRComments, + return command.ProjectCommandOutput{ + PlanSuccess: planSuccess, + Error: err, + Failure: failure, } } // PolicyCheck evaluates policies defined with Rego for the project described by ctx. -func (p *DefaultProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectCommandOutput { policySuccess, failure, err := p.doPolicyCheck(ctx) - return command.ProjectResult{ - Command: command.PolicyCheck, + return command.ProjectCommandOutput{ PolicyCheckResults: policySuccess, Error: err, Failure: failure, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, } } // Apply runs terraform apply for the project described by ctx. -func (p *DefaultProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectCommandOutput { applyOut, failure, err := p.doApply(ctx) - return command.ProjectResult{ - Command: command.Apply, - Failure: failure, - Error: err, - ApplySuccess: applyOut, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, - SilencePRComments: ctx.SilencePRComments, + return command.ProjectCommandOutput{ + Failure: failure, + Error: err, + ApplySuccess: applyOut, } } -func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectCommandOutput { approvedOut, failure, err := p.doApprovePolicies(ctx) - return command.ProjectResult{ - Command: command.PolicyCheck, + return command.ProjectCommandOutput{ Failure: failure, Error: err, PolicyCheckResults: approvedOut, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, } } -func (p *DefaultProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectCommandOutput { versionOut, failure, err := p.doVersion(ctx) - return command.ProjectResult{ - Command: command.Version, + return command.ProjectCommandOutput{ Failure: failure, Error: err, VersionSuccess: versionOut, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, } } // Import runs terraform import for the project described by ctx. -func (p *DefaultProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectCommandOutput { importSuccess, failure, err := p.doImport(ctx) - return command.ProjectResult{ - Command: command.Import, + return command.ProjectCommandOutput{ ImportSuccess: importSuccess, Error: err, Failure: failure, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, } } // StateRm runs terraform state rm for the project described by ctx. -func (p *DefaultProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectResult { +func (p *DefaultProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectCommandOutput { stateRmSuccess, failure, err := p.doStateRm(ctx) - return command.ProjectResult{ - Command: command.State, - SubCommand: "rm", + return command.ProjectCommandOutput{ StateRmSuccess: stateRmSuccess, Error: err, Failure: failure, - RepoRelDir: ctx.RepoRelDir, - Workspace: ctx.Workspace, - ProjectName: ctx.ProjectName, } } diff --git a/server/events/project_command_runner_test.go b/server/events/project_command_runner_test.go index 36bcbf90b7..883ffc8943 100644 --- a/server/events/project_command_runner_test.go +++ b/server/events/project_command_runner_test.go @@ -179,7 +179,7 @@ func TestProjectOutputWrapper(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - var prjResult command.ProjectResult + var prjResult command.ProjectCommandOutput var expCommitStatus models.CommitStatus mockJobURLSetter := mocks.NewMockJobURLSetter() @@ -193,18 +193,18 @@ func TestProjectOutputWrapper(t *testing.T) { } if c.Success { - prjResult = command.ProjectResult{ + prjResult = command.ProjectCommandOutput{ PlanSuccess: &models.PlanSuccess{}, ApplySuccess: "exists", } expCommitStatus = models.SuccessCommitStatus } else if c.Failure { - prjResult = command.ProjectResult{ + prjResult = command.ProjectCommandOutput{ Failure: "failure", } expCommitStatus = models.FailedCommitStatus } else if c.Error { - prjResult = command.ProjectResult{ + prjResult = command.ProjectCommandOutput{ Error: errors.New("error"), } expCommitStatus = models.FailedCommitStatus diff --git a/server/jobs/job_url_setter.go b/server/jobs/job_url_setter.go index 9567b87e00..fdb655eba3 100644 --- a/server/jobs/job_url_setter.go +++ b/server/jobs/job_url_setter.go @@ -20,7 +20,7 @@ type ProjectJobURLGenerator interface { type ProjectStatusUpdater interface { // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) error + UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) error } type JobURLSetter struct { @@ -35,7 +35,7 @@ func NewJobURLSetter(projectJobURLGenerator ProjectJobURLGenerator, projectStatu } } -func (j *JobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, result *command.ProjectResult) error { +func (j *JobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, result *command.ProjectCommandOutput) error { url, err := j.projectJobURLGenerator.GenerateProjectJobURL(ctx) if err != nil { diff --git a/server/jobs/job_url_setter_test.go b/server/jobs/job_url_setter_test.go index b0ca28e41e..c07e0e63de 100644 --- a/server/jobs/job_url_setter_test.go +++ b/server/jobs/job_url_setter_test.go @@ -25,7 +25,7 @@ func TestJobURLSetter(t *testing.T) { projectJobURLGenerator := mocks.NewMockProjectJobURLGenerator() url := "url-to-project-jobs" jobURLSetter := jobs.NewJobURLSetter(projectJobURLGenerator, projectStatusUpdater) - result := &command.ProjectResult{} + result := &command.ProjectCommandOutput{} When(projectJobURLGenerator.GenerateProjectJobURL(Eq[command.ProjectContext](ctx))).ThenReturn(url, nil) When(projectStatusUpdater.UpdateProject(ctx, command.Plan, models.PendingCommitStatus, url, nil)).ThenReturn(nil) diff --git a/server/jobs/mocks/mock_project_status_updater.go b/server/jobs/mocks/mock_project_status_updater.go index e28a64ee89..9958ab0596 100644 --- a/server/jobs/mocks/mock_project_status_updater.go +++ b/server/jobs/mocks/mock_project_status_updater.go @@ -26,7 +26,7 @@ func NewMockProjectStatusUpdater(options ...pegomock.Option) *MockProjectStatusU func (mock *MockProjectStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) error { +func (mock *MockProjectStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectStatusUpdater().") } @@ -78,7 +78,7 @@ type VerifierMockProjectStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectResult) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, res *command.ProjectCommandOutput) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { _params := []pegomock.Param{ctx, cmdName, status, url, res} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", _params, verifier.timeout) return &MockProjectStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -89,12 +89,12 @@ type MockProjectStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string, *command.ProjectResult) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string, *command.ProjectCommandOutput) { ctx, cmdName, status, url, res := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], url[len(url)-1], res[len(res)-1] } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectResult) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectCommandOutput) { _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(_params) > 0 { if len(_params) > 0 { @@ -122,9 +122,9 @@ func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCaptu } } if len(_params) > 4 { - _param4 = make([]*command.ProjectResult, len(c.methodInvocations)) + _param4 = make([]*command.ProjectCommandOutput, len(c.methodInvocations)) for u, param := range _params[4] { - _param4[u] = param.(*command.ProjectResult) + _param4[u] = param.(*command.ProjectCommandOutput) } } }