Skip to content
Open
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
108 changes: 0 additions & 108 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,114 +1068,6 @@ func TestRunGenericPlanCommand_DiscardApprovals(t *testing.T) {
vcsClient.VerifyWasCalledOnce().DiscardReviews(Any[logging.SimpleLogging](), Any[models.Repo](), Any[models.PullRequest]())
}

func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) {
t.Log("if \"atlantis approve_policies\" is run by non policy owner policy check status fails.")
setup(t)
tmp := t.TempDir()
boltDB, err := boltdb.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Database = boltDB
applyCommandRunner.Database = boltDB
autoMerger.GlobalAutomerge = true
defer func() { autoMerger.GlobalAutomerge = false }()

pull := &github.PullRequest{
State: github.Ptr("open"),
}

modelPull := models.PullRequest{
BaseRepo: testdata.GithubRepo,
State: models.OpenPullState,
Num: testdata.Pull.Num,
}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil)

When(projectCommandBuilder.BuildApprovePoliciesCommands(Any[*command.Context](), Any[*events.CommentCommand]())).ThenReturn([]command.ProjectContext{
{
CommandName: command.ApprovePolicies,
},
{
CommandName: command.ApprovePolicies,
},
}, nil)

When(workingDir.GetPullDir(testdata.GithubRepo, testdata.Pull)).ThenReturn(tmp, nil)

ch.RunCommentCommand(testdata.GithubRepo, &testdata.GithubRepo, &testdata.Pull, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.ApprovePolicies})
commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount(
Any[logging.SimpleLogging](),
Any[models.Repo](),
Any[models.PullRequest](),
Eq[models.CommitStatus](models.SuccessCommitStatus),
Eq[command.Name](command.PolicyCheck),
Eq(0),
Eq(2),
)
}

func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) {
t.Log("if \"atlantis approve_policies\" is run by policy owner all policy checks are approved.")
setup(t)
tmp := t.TempDir()
boltDB, err := boltdb.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Database = boltDB
applyCommandRunner.Database = boltDB
autoMerger.GlobalAutomerge = true
defer func() { autoMerger.GlobalAutomerge = false }()

pull := &github.PullRequest{
State: github.Ptr("open"),
}

modelPull := models.PullRequest{
BaseRepo: testdata.GithubRepo,
State: models.OpenPullState,
Num: testdata.Pull.Num,
}
When(githubGetter.GetPullRequest(Any[logging.SimpleLogging](), Eq(testdata.GithubRepo), Eq(testdata.Pull.Num))).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(Any[logging.SimpleLogging](), Eq(pull))).ThenReturn(modelPull, modelPull.BaseRepo, testdata.GithubRepo, nil)

When(projectCommandBuilder.BuildApprovePoliciesCommands(Any[*command.Context](), Any[*events.CommentCommand]())).ThenReturn([]command.ProjectContext{
{
CommandName: command.ApprovePolicies,
PolicySets: valid.PolicySets{
Owners: valid.PolicyOwners{
Users: []string{testdata.User.Username},
},
},
},
}, nil)

When(workingDir.GetPullDir(testdata.GithubRepo, testdata.Pull)).ThenReturn(tmp, nil)
When(projectCommandRunner.ApprovePolicies(Any[command.ProjectContext]())).Then(func(_ []Param) ReturnValues {
return ReturnValues{
command.ProjectResult{
Command: command.PolicyCheck,
PolicyCheckResults: &models.PolicyCheckResults{},
},
}
})

ch.RunCommentCommand(testdata.GithubRepo, &testdata.GithubRepo, &testdata.Pull, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.ApprovePolicies})
commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount(
Any[logging.SimpleLogging](),
Any[models.Repo](),
Any[models.PullRequest](),
Eq[models.CommitStatus](models.SuccessCommitStatus),
Eq[command.Name](command.PolicyCheck),
Eq(1),
Eq(1),
)
}

func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) {
t.Log("if \"atlantis apply\" is run with failing policy check then apply is not performed")
setup(t)
Expand Down
Loading