From d98474a4aa523f391acb37dfe2c48ad2b86be28b Mon Sep 17 00:00:00 2001 From: Marc Barlo Date: Mon, 10 May 2021 16:33:21 -0700 Subject: [PATCH] Fix ParallelPlan and ParallelApply out of order in buildProjectCommandCtx (#1574) * Fix regression - paralle plan / apply out-of-order * Add test to check we're correctly setting ParallelPlan/Apply * Add project command builder tests to check args * rm vendor --- server/events/project_command_builder.go | 4 +- server/events/project_command_builder_test.go | 45 +++++++++++++++---- .../events/project_command_context_builder.go | 2 +- .../project_command_context_builder_test.go | 21 +++++++++ 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 3f28e64470..fc7c9b6f16 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -482,8 +482,8 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *CommandContex repoDir, automerge, projCfg.DeleteSourceBranchOnMerge, - parallelPlan, parallelApply, + parallelPlan, verbose, )...) } @@ -498,8 +498,8 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *CommandContex repoDir, automerge, projCfg.DeleteSourceBranchOnMerge, - parallelPlan, parallelApply, + parallelPlan, verbose, )...) } diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 87907eb8fb..f39d52dd49 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -170,15 +170,17 @@ projects: // Test building a plan and apply command for one project. func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T) { cases := []struct { - Description string - AtlantisYAML string - Cmd events.CommentCommand - ExpCommentArgs []string - ExpWorkspace string - ExpDir string - ExpProjectName string - ExpErr string - ExpApplyReqs []string + Description string + AtlantisYAML string + Cmd events.CommentCommand + ExpCommentArgs []string + ExpWorkspace string + ExpDir string + ExpProjectName string + ExpErr string + ExpApplyReqs []string + ExpParallelApply bool + ExpParallelPlan bool }{ { Description: "no atlantis.yaml", @@ -342,6 +344,29 @@ projects: `, ExpErr: "no project with name \"notconfigured\" is defined in atlantis.yaml", }, + { + Description: "atlantis.yaml with ParallelPlan Set to true", + Cmd: events.CommentCommand{ + Name: models.PlanCommand, + RepoRelDir: ".", + Workspace: "default", + ProjectName: "myproject", + }, + AtlantisYAML: ` +version: 3 +parallel_plan: true +projects: +- name: myproject + dir: . + workspace: myworkspace +`, + ExpParallelPlan: true, + ExpParallelApply: false, + ExpDir: ".", + ExpWorkspace: "myworkspace", + ExpProjectName: "myproject", + ExpApplyReqs: []string{}, + }, } logger := logging.NewNoopLogger(t) @@ -403,6 +428,8 @@ projects: Equals(t, c.ExpCommentArgs, actCtx.EscapedCommentArgs) Equals(t, c.ExpProjectName, actCtx.ProjectName) Equals(t, c.ExpApplyReqs, actCtx.ApplyRequirements) + Equals(t, c.ExpParallelApply, actCtx.ParallelApplyEnabled) + Equals(t, c.ExpParallelPlan, actCtx.ParallelPlanEnabled) }) } } diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index f681ec4df7..f269a68258 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -33,7 +33,7 @@ type ProjectCommandContextBuilder interface { prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, - automerge, deleteSourceBranchOnMerge, parallelPlan, parallelApply, verbose bool, + automerge, deleteSourceBranchOnMerge, parallelApply, parallelPlan, verbose bool, ) []models.ProjectCommandContext } diff --git a/server/events/project_command_context_builder_test.go b/server/events/project_command_context_builder_test.go index d0a3de9bdd..ee85eabb74 100644 --- a/server/events/project_command_context_builder_test.go +++ b/server/events/project_command_context_builder_test.go @@ -81,4 +81,25 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { assert.Equal(t, models.ErroredPolicyCheckStatus, result[0].ProjectPlanStatus) }) + + t.Run("when ParallelApply is set to true", func(t *testing.T) { + projCfg.Name = "Apply Comment" + When(mockCommentBuilder.BuildPlanComment(projRepoRelDir, projWorkspace, "", []string{})).ThenReturn(expectedPlanCmt) + When(mockCommentBuilder.BuildApplyComment(projRepoRelDir, projWorkspace, "")).ThenReturn(expectedApplyCmt) + pullStatus.Projects = []models.ProjectStatus{ + { + Status: models.ErroredPlanStatus, + RepoRelDir: "dir2", + }, + { + Status: models.ErroredPolicyCheckStatus, + RepoRelDir: "dir1", + }, + } + + result := subject.BuildProjectContext(commandCtx, models.PlanCommand, projCfg, []string{}, "some/dir", false, false, true, false, false) + + assert.True(t, result[0].ParallelApplyEnabled) + assert.False(t, result[0].ParallelPlanEnabled) + }) }