mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-02 03:58:40 +00:00
* chore: trim space rendered templates * regen e2e results * revert parallel output substring check test case * follow master branch * follow main branch * Update approve_policies_command_runner_test.go Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
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:",
|
|
},
|
|
{
|
|
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.",
|
|
},
|
|
}
|
|
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")
|
|
})
|
|
}
|
|
}
|