This commit is contained in:
Luke Kysow
2018-06-21 18:27:03 +01:00
parent d3ec832eff
commit 124a016f08
5 changed files with 34 additions and 20 deletions

View File

@@ -153,7 +153,7 @@ func (p *ProjectCommandRunner) Apply(ctx models.ProjectCommandContext) ProjectCo
for _, req := range ctx.ProjectConfig.ApplyRequirements {
switch req {
case "approved":
approved, err := p.PullApprovedChecker.IsApproved(ctx.BaseRepo, ctx.Pull)
approved, err := p.PullApprovedChecker.PullIsApproved(ctx.BaseRepo, ctx.Pull)
if err != nil {
return ProjectCommandResult{Error: errors.Wrap(err, "checking if pull request was approved")}
}

View File

@@ -65,6 +65,33 @@ func TestRun_Success(t *testing.T) {
terraform.VerifyWasCalledOnce().RunCommandWithVersion(nil, tmpDir, []string{"apply", "-no-color", "extra", "args", "comment", "args", planPath}, nil, "workspace")
}
func TestRun_AppliesCorrectProjectPlan(t *testing.T) {
// When running for a project, the planfile has a different name.
tmpDir, cleanup := TempDir(t)
defer cleanup()
planPath := filepath.Join(tmpDir, "projectname-default.tfplan")
err := ioutil.WriteFile(planPath, nil, 0644)
Ok(t, err)
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
o := runtime.ApplyStepRunner{
TerraformExecutor: terraform,
}
When(terraform.RunCommandWithVersion(matchers.AnyPtrToLoggingSimpleLogger(), AnyString(), AnyStringSlice(), matchers2.AnyPtrToGoVersionVersion(), AnyString())).
ThenReturn("output", nil)
output, err := o.Run(models.ProjectCommandContext{
Workspace: "default",
RepoRelPath: ".",
ProjectName: "projectname",
CommentArgs: []string{"comment", "args"},
}, []string{"extra", "args"}, tmpDir)
Ok(t, err)
Equals(t, "output", output)
terraform.VerifyWasCalledOnce().RunCommandWithVersion(nil, tmpDir, []string{"apply", "-no-color", "extra", "args", "comment", "args", planPath}, nil, "default")
}
func TestRun_UsesConfiguredTFVersion(t *testing.T) {
tmpDir, cleanup := TempDir(t)
defer cleanup()

View File

@@ -2,17 +2,8 @@ package runtime
import (
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/vcs"
)
type PullApprovedChecker struct {
VCSClient vcs.ClientProxy
}
func (a *PullApprovedChecker) IsApproved(baseRepo models.Repo, pull models.PullRequest) (bool, error) {
approved, err := a.VCSClient.PullIsApproved(baseRepo, pull)
if err != nil {
return false, err
}
return approved, nil
type PullApprovedChecker interface {
PullIsApproved(baseRepo models.Repo, pull models.PullRequest) (bool, error)
}

View File

@@ -252,10 +252,8 @@ func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClientProxy,
ApplyStepRunner: runtime.ApplyStepRunner{
TerraformExecutor: terraformClient,
},
RunStepRunner: runtime.RunStepRunner{},
PullApprovedChecker: runtime.PullApprovedChecker{
VCSClient: e2eVCSClient,
},
RunStepRunner: runtime.RunStepRunner{},
PullApprovedChecker: e2eVCSClient,
Workspace: atlantisWorkspace,
Webhooks: &mockWebhookSender{},
AtlantisWorkspaceLocker: locker,

View File

@@ -251,10 +251,8 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
ApplyStepRunner: runtime.ApplyStepRunner{
TerraformExecutor: terraformClient,
},
RunStepRunner: runtime.RunStepRunner{},
PullApprovedChecker: runtime.PullApprovedChecker{
VCSClient: vcsClient,
},
RunStepRunner: runtime.RunStepRunner{},
PullApprovedChecker: vcsClient,
Workspace: workspace,
Webhooks: webhooksManager,
AtlantisWorkspaceLocker: workspaceLocker,