forked from runatlantis/atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set ctx.PullRequestStatus in import_command_runner for import_re…
…quirements (runatlantis#2936) * refactor: pull_status_fetcher contains vcsStatusName in struct / reduce FetchPullStatus parameter * import_command_runner need to set ctx.PullRequestStatus for import_requirements
- Loading branch information
Showing
9 changed files
with
256 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package events_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/petergtz/pegomock" | ||
"github.com/runatlantis/atlantis/server/events" | ||
"github.com/runatlantis/atlantis/server/events/command" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
"github.com/runatlantis/atlantis/server/events/models/fixtures" | ||
"github.com/runatlantis/atlantis/server/logging" | ||
"github.com/runatlantis/atlantis/server/metrics" | ||
. "github.com/runatlantis/atlantis/testing" | ||
) | ||
|
||
func TestImportCommandRunner_Run(t *testing.T) { | ||
RegisterMockTestingT(t) | ||
|
||
tests := []struct { | ||
name string | ||
pullReqStatus models.PullReqStatus | ||
projectCmds []command.ProjectContext | ||
expComment string | ||
}{ | ||
{ | ||
name: "success with zero projects", | ||
pullReqStatus: models.PullReqStatus{ | ||
ApprovalStatus: models.ApprovalStatus{IsApproved: true}, | ||
Mergeable: true, | ||
}, | ||
projectCmds: []command.ProjectContext{}, | ||
expComment: "Ran Import for 0 projects:\n\n\n\n", | ||
}, | ||
{ | ||
name: "failure with multiple projects", | ||
pullReqStatus: models.PullReqStatus{ | ||
ApprovalStatus: models.ApprovalStatus{IsApproved: true}, | ||
Mergeable: true, | ||
}, | ||
projectCmds: []command.ProjectContext{{}, {}}, | ||
expComment: "**Import Failed**: import cannot run on multiple projects. please specify one project.\n", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
vcsClient := setup(t) | ||
|
||
scopeNull, _, _ := metrics.NewLoggingScope(logger, "atlantis") | ||
modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} | ||
ctx := &command.Context{ | ||
User: fixtures.User, | ||
Log: logging.NewNoopLogger(t), | ||
Scope: scopeNull, | ||
Pull: modelPull, | ||
HeadRepo: fixtures.GithubRepo, | ||
Trigger: command.CommentTrigger, | ||
} | ||
cmd := &events.CommentCommand{Name: command.Import} | ||
|
||
When(pullReqStatusFetcher.FetchPullStatus(modelPull)).ThenReturn(tt.pullReqStatus, nil) | ||
When(projectCommandBuilder.BuildImportCommands(ctx, cmd)).ThenReturn(tt.projectCmds, nil) | ||
|
||
importCommandRunner.Run(ctx, cmd) | ||
|
||
Assert(t, ctx.PullRequestStatus.Mergeable == true, "PullRequestStatus must be set for import_requirements") | ||
vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, tt.expComment, "import") | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
server/events/vcs/mocks/mock_pull_req_status_fetcher.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.