Skip to content

Commit

Permalink
Fix ParallelPlan and ParallelApply out of order in buildProjectComman…
Browse files Browse the repository at this point in the history
…dCtx (#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
  • Loading branch information
Fauzyy authored May 10, 2021
1 parent 429235d commit d98474a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
4 changes: 2 additions & 2 deletions server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *CommandContex
repoDir,
automerge,
projCfg.DeleteSourceBranchOnMerge,
parallelPlan,
parallelApply,
parallelPlan,
verbose,
)...)
}
Expand All @@ -498,8 +498,8 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *CommandContex
repoDir,
automerge,
projCfg.DeleteSourceBranchOnMerge,
parallelPlan,
parallelApply,
parallelPlan,
verbose,
)...)
}
Expand Down
45 changes: 36 additions & 9 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/events/project_command_context_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 21 additions & 0 deletions server/events/project_command_context_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit d98474a

Please sign in to comment.