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

Fixes #1006: Keep track of project status even if plans have been deleted #1005

Merged
merged 12 commits into from
Jun 24, 2020
34 changes: 0 additions & 34 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ import (
. "github.com/petergtz/pegomock"
"github.com/runatlantis/atlantis/server/events"
dbmocks "github.com/runatlantis/atlantis/server/events/db/mocks"
dbmatchers "github.com/runatlantis/atlantis/server/events/db/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/mocks"
"github.com/runatlantis/atlantis/server/events/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/models"
@@ -256,36 +255,3 @@ func TestApplyWithAutoMerge_VSCMerge(t *testing.T) {
ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand})
vcsClient.VerifyWasCalledOnce().MergePull(modelPull)
lkysow marked this conversation as resolved.
Show resolved Hide resolved
}

func TestApplyWithAutoMerge_DiscardedPlan(t *testing.T) {
t.Log("if \"atlantis apply\" is run with automerge and at least one project" +
" has a discarded plan, automerge should not take place")

setup(t)
pull := &github.PullRequest{
State: github.String("open"),
}
modelPull := models.PullRequest{State: models.OpenPullState}
When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil)
When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil)
ch.GlobalAutomerge = true

ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand})
projectStatuses := []models.ProjectStatus{
{
RepoRelDir: ".",
Workspace: "default",
ProjectName: "automerge-test",
Status: models.DiscardedPlanStatus,
},
}
pullStatus := models.PullStatus{
Projects: projectStatuses,
Pull: modelPull,
}
//When(boltDB.UpdatePullWithResults(modelPull, nil)).ThenReturn(pullStatus, nil)
When(boltDB.UpdatePullWithResults(dbmatchers.EqModelsPullRequest(modelPull), dbmatchers.EqSliceOfModelsProjectResult(nil))).ThenReturn(pullStatus, nil)
// TODO: stubbing here doesn't seem to work? pullStatus defined here is not actually returned and so I cannot uncomment the next two lines which would verify our scenario here
//vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, "not automerging because project at dir %q, workspace %q has status %q")
//VerifyWasCalled(Never()).MergePull(modelPull)
}
6 changes: 6 additions & 0 deletions server/events/db/boltdb.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,12 @@ import (

// BoltDB interface defines the set of methods the DB implements. Use this to allow DB mocking when testing
type BoltDB interface {
TryLock(newLock models.ProjectLock) (bool, models.ProjectLock, error)
Unlock(p models.Project, workspace string) (*models.ProjectLock, error)
List() ([]models.ProjectLock, error)
UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
GetLock(p models.Project, workspace string) (*models.ProjectLock, error)
GetPullStatus(pull models.PullRequest) (*models.PullStatus, error)
UpdatePullWithResults(pull models.PullRequest, newResults []models.ProjectResult) (models.PullStatus, error)
DeletePullStatus(pull models.PullRequest) error
UpdateProjectStatus(pull models.PullRequest, workspace string, repoRelDir string, targetStatus models.ProjectPlanStatus) error
20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/models_project.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/models_projectlock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/models_projectresult.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/models_projectstatus.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/ptr_to_bbolt_bucket.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/ptr_to_models_projectlock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/ptr_to_models_pullstatus.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/slice_of_byte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/events/db/mocks/matchers/slice_of_models_projectlock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

282 changes: 282 additions & 0 deletions server/events/db/mocks/mock_boltdb.go