-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global atlantis lock new release branch (#1473)
* Orca 679 global atlantis lock new release branch (#49) * Adding CommandLocker to boltDB and exposing it through locker interface * Apply lock ui and apply command lock controller * Minor comments * Adding more tests and refactorinng * Linting fixes * creating applyLockingClient variable to fix interface error * nullsink for stats * Addressing PR comments * fixing e2e tests * linting fix fml * Update outdated function descriptions Address PR comments * revert stats sink changes * remove unnecessary dependencies
- Loading branch information
Showing
25 changed files
with
1,460 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package events_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/google/go-github/v31/github" | ||
. "github.com/petergtz/pegomock" | ||
"github.com/runatlantis/atlantis/server/events" | ||
"github.com/runatlantis/atlantis/server/events/locking" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
"github.com/runatlantis/atlantis/server/events/models/fixtures" | ||
) | ||
|
||
func TestApplyCommandRunner_IsLocked(t *testing.T) { | ||
RegisterMockTestingT(t) | ||
|
||
cases := []struct { | ||
Description string | ||
ApplyLocked bool | ||
ApplyLockError error | ||
ExpComment string | ||
}{ | ||
{ | ||
Description: "When global apply lock is present IsDisabled returns true", | ||
ApplyLocked: true, | ||
ApplyLockError: nil, | ||
ExpComment: "**Error:** Running `atlantis apply` is disabled.", | ||
}, | ||
{ | ||
Description: "When no global apply lock is present and DisableApply flag is false IsDisabled returns false", | ||
ApplyLocked: false, | ||
ApplyLockError: nil, | ||
ExpComment: "Ran Apply for 0 projects:\n\n\n\n", | ||
}, | ||
{ | ||
Description: "If ApplyLockChecker returns an error IsDisabled return value of DisableApply flag", | ||
ApplyLockError: errors.New("error"), | ||
ApplyLocked: false, | ||
ExpComment: "Ran Apply for 0 projects:\n\n\n\n", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.Description, func(t *testing.T) { | ||
vcsClient := setup(t) | ||
|
||
pull := &github.PullRequest{ | ||
State: github.String("open"), | ||
} | ||
modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} | ||
When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil) | ||
When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) | ||
|
||
ctx := &events.CommandContext{ | ||
User: fixtures.User, | ||
Log: noopLogger, | ||
Pull: modelPull, | ||
HeadRepo: fixtures.GithubRepo, | ||
Trigger: events.Comment, | ||
} | ||
|
||
When(applyLockChecker.CheckApplyLock()).ThenReturn(locking.ApplyCommandLock{Locked: c.ApplyLocked}, c.ApplyLockError) | ||
applyCommandRunner.Run(ctx, &events.CommentCommand{Name: models.ApplyCommand}) | ||
|
||
vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, c.ExpComment, "apply") | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.