Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ParallelPlan and ParallelApply out of order in buildProjectCommandCtx #1574

Merged
merged 5 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}