From f32d97b5272bdba9834520324d2de697ca17b2e7 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Mon, 13 Jun 2022 17:16:13 -0400 Subject: [PATCH] test: update tests per command package refactoring (#2317) --- server/events/command_runner_test.go | 16 ++++++++-------- server/events/event_parser_test.go | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index 9bbc324499..5f203e9be4 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -540,15 +540,15 @@ func TestRunAutoplanCommand_DeleteLocksByPull(t *testing.T) { defer func() { autoMerger.GlobalAutomerge = false }() When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). - ThenReturn([]models.ProjectCommandContext{ + ThenReturn([]command.ProjectContext{ { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, }, nil) - When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(models.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil) fixtures.Pull.BaseRepo = fixtures.GithubRepo ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User) @@ -566,7 +566,7 @@ func TestRunGenericPlanCommand_DeleteLocksByPull(t *testing.T) { autoMerger.GlobalAutomerge = true defer func() { autoMerger.GlobalAutomerge = false }() - When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(models.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil) pull := &github.PullRequest{State: github.String("open")} modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} @@ -574,7 +574,7 @@ func TestRunGenericPlanCommand_DeleteLocksByPull(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) fixtures.Pull.BaseRepo = fixtures.GithubRepo - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.PlanCommand}) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan}) deleteLockCommand.VerifyWasCalledOnce().DeleteLocksByPull(fixtures.Pull.BaseRepo.FullName, fixtures.Pull.Num) } @@ -589,10 +589,10 @@ func TestRunSpecificPlanCommandDoesnt_DeleteLocksByPull(t *testing.T) { autoMerger.GlobalAutomerge = true defer func() { autoMerger.GlobalAutomerge = false }() - When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(models.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) + When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}}) When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil) fixtures.Pull.BaseRepo = fixtures.GithubRepo - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.PlanCommand, ProjectName: "default"}) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan, ProjectName: "default"}) deleteLockCommand.VerifyWasCalled(Never()).DeleteLocksByPull(fixtures.Pull.BaseRepo.FullName, fixtures.Pull.Num) } diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index 3c9e58c4a1..d3e979a473 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -16,6 +16,7 @@ package events_test import ( "encoding/json" "fmt" + "io/ioutil" "os" "path/filepath" "strings"