Skip to content

Commit

Permalink
Execute against pull_request (#66)
Browse files Browse the repository at this point in the history
* Fix failing tests

* Regenerate mocks

* Use pull request, not pull request target
  • Loading branch information
Dragos Dumitrache authored Jan 31, 2023
1 parent e9f4378 commit 75794db
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
paths:
- '**/*.go'
- '.github/workflows/test.yml'
pull_request_target:
pull_request:
types:
- opened
- reopened
Expand All @@ -27,7 +27,7 @@ concurrency:

jobs:
test:
if: github.event.pull_request_target.draft == false
if: github.event.pull_request.draft == false
name: runner / gotest
runs-on: ubuntu-22.04
container: ghcr.io/runatlantis/testing-env:latest
Expand All @@ -40,7 +40,7 @@ jobs:
# This job builds the website, starts a server to serve it, and then uses
# muffet (https://github.com/raviqqe/muffet) to perform the link check.
website_link_check:
if: github.event.pull_request_target.draft == false
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions server/events/github_app_working_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func TestClone_GithubAppSetsCorrectUrl(t *testing.T) {
modifiedBaseRepo.SanitizedCloneURL = "https://x-access-token:<redacted>@github.com/runatlantis/atlantis.git"

When(credentials.GetToken()).ThenReturn("token", nil)
When(workingDir.Clone(logger, modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default")).ThenReturn(
When(workingDir.Clone(logger, modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default", []string{})).ThenReturn(
"", true, nil,
)

_, success, _ := ghAppWorkingDir.Clone(logger, headRepo, models.PullRequest{BaseRepo: baseRepo}, "default")
_, success, _ := ghAppWorkingDir.Clone(logger, headRepo, models.PullRequest{BaseRepo: baseRepo}, "default", []string{})

Assert(t, success == true, "clone url mutation error")
}
15 changes: 13 additions & 2 deletions server/events/matchers/slice_of_string.go

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

18 changes: 9 additions & 9 deletions server/events/mock_workingdir_test.go

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

14 changes: 7 additions & 7 deletions server/events/mocks/mock_working_dir.go

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

12 changes: 6 additions & 6 deletions server/events/post_workflow_hooks_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestRunPostHooks_Clone(t *testing.T) {
postWh.GlobalCfg = globalCfg

When(postWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPostWorkflowHookRunner.Run(pCtx, testHook.RunCommand, repoDir)).ThenReturn(result, runtimeDesc, nil)

err := postWh.RunPostHooks(ctx, nil)
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestRunPostHooks_Clone(t *testing.T) {

whPostWorkflowHookRunner.VerifyWasCalled(Never()).Run(pCtx, testHook.RunCommand, repoDir)
postWhWorkingDirLocker.VerifyWasCalled(Never()).TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, "path")
postWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)
postWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})
})
t.Run("error locking work dir", func(t *testing.T) {
postWorkflowHooksSetup(t)
Expand All @@ -159,7 +159,7 @@ func TestRunPostHooks_Clone(t *testing.T) {
err := postWh.RunPostHooks(ctx, nil)

Assert(t, err != nil, "error not nil")
postWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)
postWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})
whPostWorkflowHookRunner.VerifyWasCalled(Never()).Run(pCtx, testHook.RunCommand, repoDir)
})

Expand All @@ -185,7 +185,7 @@ func TestRunPostHooks_Clone(t *testing.T) {
postWh.GlobalCfg = globalCfg

When(postWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, errors.New("some error"))
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, errors.New("some error"))

err := postWh.RunPostHooks(ctx, nil)

Expand Down Expand Up @@ -217,7 +217,7 @@ func TestRunPostHooks_Clone(t *testing.T) {
postWh.GlobalCfg = globalCfg

When(postWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPostWorkflowHookRunner.Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))).ThenReturn(result, runtimeDesc, errors.New("some error"))

err := postWh.RunPostHooks(ctx, nil)
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestRunPostHooks_Clone(t *testing.T) {
postWh.GlobalCfg = globalCfg

When(postWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(postWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPostWorkflowHookRunner.Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))).ThenReturn(result, runtimeDesc, nil)

err := postWh.RunPostHooks(ctx, cmd)
Expand Down
12 changes: 6 additions & 6 deletions server/events/pre_workflow_hooks_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestRunPreHooks_Clone(t *testing.T) {
preWh.GlobalCfg = globalCfg

When(preWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPreWorkflowHookRunner.Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))).ThenReturn(result, runtimeDesc, nil)

err := preWh.RunPreHooks(ctx, nil)
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestRunPreHooks_Clone(t *testing.T) {

whPreWorkflowHookRunner.VerifyWasCalled(Never()).Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))
preWhWorkingDirLocker.VerifyWasCalled(Never()).TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, "")
preWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)
preWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})
})

t.Run("error locking work dir", func(t *testing.T) {
Expand All @@ -162,7 +162,7 @@ func TestRunPreHooks_Clone(t *testing.T) {
err := preWh.RunPreHooks(ctx, nil)

Assert(t, err != nil, "error not nil")
preWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)
preWhWorkingDir.VerifyWasCalled(Never()).Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})
whPreWorkflowHookRunner.VerifyWasCalled(Never()).Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))
})

Expand All @@ -188,7 +188,7 @@ func TestRunPreHooks_Clone(t *testing.T) {
preWh.GlobalCfg = globalCfg

When(preWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, errors.New("some error"))
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, errors.New("some error"))

err := preWh.RunPreHooks(ctx, nil)

Expand Down Expand Up @@ -220,7 +220,7 @@ func TestRunPreHooks_Clone(t *testing.T) {
preWh.GlobalCfg = globalCfg

When(preWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPreWorkflowHookRunner.Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))).ThenReturn(result, runtimeDesc, errors.New("some error"))

err := preWh.RunPreHooks(ctx, nil)
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestRunPreHooks_Clone(t *testing.T) {
preWh.GlobalCfg = globalCfg

When(preWhWorkingDirLocker.TryLock(testdata.GithubRepo.FullName, newPull.Num, events.DefaultWorkspace, events.DefaultRepoRelDir)).ThenReturn(unlockFn, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace)).ThenReturn(repoDir, false, nil)
When(preWhWorkingDir.Clone(log, testdata.GithubRepo, newPull, events.DefaultWorkspace, []string{})).ThenReturn(repoDir, false, nil)
When(whPreWorkflowHookRunner.Run(runtimematchers.AnyModelsWorkflowHookCommandContext(), EqString(testHook.RunCommand), EqString(repoDir))).ThenReturn(result, runtimeDesc, nil)

err := preWh.RunPreHooks(ctx, cmd)
Expand Down
6 changes: 3 additions & 3 deletions server/events/project_command_builder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ projects:
})

workingDir := NewMockWorkingDir()
When(workingDir.Clone(logging_matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString())).ThenReturn(tmp, false, nil)
When(workingDir.Clone(logging_matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString(), AnyStringSlice())).ThenReturn(tmp, false, nil)
vcsClient := vcsmocks.NewMockClient()
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{"modules/module/main.tf"}, nil)

Expand Down Expand Up @@ -1073,7 +1073,7 @@ workflows:
})

workingDir := NewMockWorkingDir()
When(workingDir.Clone(matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString())).ThenReturn(tmp, false, nil)
When(workingDir.Clone(matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString(), AnyStringSlice())).ThenReturn(tmp, false, nil)
vcsClient := vcsmocks.NewMockClient()
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{"modules/module/main.tf"}, nil)

Expand Down Expand Up @@ -1225,7 +1225,7 @@ projects:
})

workingDir := NewMockWorkingDir()
When(workingDir.Clone(matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString())).ThenReturn(tmp, false, nil)
When(workingDir.Clone(matchers.AnyLoggingSimpleLogging(), matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), AnyString(), AnyStringSlice())).ThenReturn(tmp, false, nil)
vcsClient := vcsmocks.NewMockClient()
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{"modules/module/main.tf"}, nil)

Expand Down
Loading

0 comments on commit 75794db

Please sign in to comment.