@@ -338,7 +338,7 @@ func TestRunCommentCommand_ForkPRDisabled(t *testing.T) {
338
338
headRepo .Owner = "forkrepo"
339
339
When (eventParsing .ParseGithubPull (& pull )).ThenReturn (modelPull , modelPull .BaseRepo , headRepo , nil )
340
340
341
- ch .RunCommentCommand (fixtures .GithubRepo , nil , nil , fixtures .User , fixtures .Pull .Num , nil )
341
+ ch .RunCommentCommand (fixtures .GithubRepo , nil , nil , fixtures .User , fixtures .Pull .Num , & events. CommentCommand { Name : command . Plan } )
342
342
commentMessage := fmt .Sprintf ("Atlantis commands can't be run on fork pull requests. To enable, set --%s or, to disable this message, set --%s" , ch .AllowForkPRsFlag , ch .SilenceForkPRErrorsFlag )
343
343
vcsClient .VerifyWasCalledOnce ().CreateComment (fixtures .GithubRepo , modelPull .Num , commentMessage , "" )
344
344
}
@@ -357,7 +357,7 @@ func TestRunCommentCommand_ForkPRDisabled_SilenceEnabled(t *testing.T) {
357
357
headRepo .Owner = "forkrepo"
358
358
When (eventParsing .ParseGithubPull (& pull )).ThenReturn (modelPull , modelPull .BaseRepo , headRepo , nil )
359
359
360
- ch .RunCommentCommand (fixtures .GithubRepo , nil , nil , fixtures .User , fixtures .Pull .Num , nil )
360
+ ch .RunCommentCommand (fixtures .GithubRepo , nil , nil , fixtures .User , fixtures .Pull .Num , & events. CommentCommand { Name : command . Plan } )
361
361
vcsClient .VerifyWasCalled (Never ()).CreateComment (matchers .AnyModelsRepo (), AnyInt (), AnyString (), AnyString ())
362
362
}
363
363
@@ -484,7 +484,7 @@ func TestRunCommentCommand_ClosedPull(t *testing.T) {
484
484
When (githubGetter .GetPullRequest (fixtures .GithubRepo , fixtures .Pull .Num )).ThenReturn (pull , nil )
485
485
When (eventParsing .ParseGithubPull (pull )).ThenReturn (modelPull , modelPull .BaseRepo , fixtures .GithubRepo , nil )
486
486
487
- ch .RunCommentCommand (fixtures .GithubRepo , & fixtures .GithubRepo , nil , fixtures .User , fixtures .Pull .Num , nil )
487
+ ch .RunCommentCommand (fixtures .GithubRepo , & fixtures .GithubRepo , nil , fixtures .User , fixtures .Pull .Num , & events. CommentCommand { Name : command . Plan } )
488
488
vcsClient .VerifyWasCalledOnce ().CreateComment (fixtures .GithubRepo , modelPull .Num , "Atlantis commands can't be run on closed pull requests" , "" )
489
489
}
490
490
@@ -523,21 +523,40 @@ func TestRunCommentCommand_UnmatchedBranch(t *testing.T) {
523
523
}
524
524
525
525
func TestRunUnlockCommand_VCSComment (t * testing.T ) {
526
- t .Log ("if unlock PR command is run, atlantis should" +
527
- " invoke the delete command and comment on PR accordingly" )
526
+ testCases := []struct {
527
+ name string
528
+ prState * string
529
+ }{
530
+ {
531
+ name : "PR open" ,
532
+ prState : github .String ("open" ),
533
+ },
528
534
529
- vcsClient := setup (t )
530
- pull := & github.PullRequest {
531
- State : github .String ("open" ),
535
+ {
536
+ name : "PR closed" ,
537
+ prState : github .String ("closed" ),
538
+ },
532
539
}
533
- modelPull := models.PullRequest {BaseRepo : fixtures .GithubRepo , State : models .OpenPullState , Num : fixtures .Pull .Num }
534
- When (githubGetter .GetPullRequest (fixtures .GithubRepo , fixtures .Pull .Num )).ThenReturn (pull , nil )
535
- When (eventParsing .ParseGithubPull (pull )).ThenReturn (modelPull , modelPull .BaseRepo , fixtures .GithubRepo , nil )
536
540
537
- ch .RunCommentCommand (fixtures .GithubRepo , & fixtures .GithubRepo , nil , fixtures .User , fixtures .Pull .Num , & events.CommentCommand {Name : command .Unlock })
541
+ for _ , tc := range testCases {
542
+ t .Run (tc .name , func (t * testing.T ) {
543
+ t .Logf ("if an unlock command is run on a pull request in state %s, atlantis should" +
544
+ " invoke the delete command and comment on PR accordingly" , * tc .prState )
538
545
539
- deleteLockCommand .VerifyWasCalledOnce ().DeleteLocksByPull (fixtures .GithubRepo .FullName , fixtures .Pull .Num )
540
- vcsClient .VerifyWasCalledOnce ().CreateComment (fixtures .GithubRepo , fixtures .Pull .Num , "All Atlantis locks for this PR have been unlocked and plans discarded" , "unlock" )
546
+ vcsClient := setup (t )
547
+ pull := & github.PullRequest {
548
+ State : tc .prState ,
549
+ }
550
+ modelPull := models.PullRequest {BaseRepo : fixtures .GithubRepo , State : models .OpenPullState , Num : fixtures .Pull .Num }
551
+ When (githubGetter .GetPullRequest (fixtures .GithubRepo , fixtures .Pull .Num )).ThenReturn (pull , nil )
552
+ When (eventParsing .ParseGithubPull (pull )).ThenReturn (modelPull , modelPull .BaseRepo , fixtures .GithubRepo , nil )
553
+
554
+ ch .RunCommentCommand (fixtures .GithubRepo , & fixtures .GithubRepo , nil , fixtures .User , fixtures .Pull .Num , & events.CommentCommand {Name : command .Unlock })
555
+
556
+ deleteLockCommand .VerifyWasCalledOnce ().DeleteLocksByPull (fixtures .GithubRepo .FullName , fixtures .Pull .Num )
557
+ vcsClient .VerifyWasCalledOnce ().CreateComment (fixtures .GithubRepo , fixtures .Pull .Num , "All Atlantis locks for this PR have been unlocked and plans discarded" , "unlock" )
558
+ })
559
+ }
541
560
}
542
561
543
562
func TestRunUnlockCommandFail_VCSComment (t * testing.T ) {
0 commit comments