|
22 | 22 | import java.util.logging.Level;
|
23 | 23 | import java.util.List;
|
24 | 24 | import java.util.ArrayList;
|
| 25 | +import java.util.Collections; |
25 | 26 |
|
26 | 27 | import static org.assertj.core.api.Assertions.assertThat;
|
27 | 28 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
@@ -221,6 +222,38 @@ void shouldScheduleRerunWhenUserHasRequiredRole() throws IOException {
|
221 | 222 | }
|
222 | 223 | }
|
223 | 224 |
|
| 225 | + @Test |
| 226 | + void shouldNotScheduleRerunWhenUserDoesNotHaveRequiredRole() throws IOException { |
| 227 | + Job job = mock(Job.class); |
| 228 | + Run run = mock(Run.class); |
| 229 | + JenkinsFacade jenkinsFacade = mock(JenkinsFacade.class); |
| 230 | + SCMFacade scmFacade = mock(SCMFacade.class); |
| 231 | + GitHubStatusChecksProperties githubStatusChecksProperties = mock(GitHubStatusChecksProperties.class); |
| 232 | + User user = mock(User.class); |
| 233 | + List<String> userRoles = Collections.<String>emptyList();; |
| 234 | + |
| 235 | + when(jenkinsFacade.getBuild("codingstyle/PR-1#2")).thenReturn(Optional.of(run)); |
| 236 | + when(jenkinsFacade.getFullNameOf(job)).thenReturn("codingstyle/PR-1"); |
| 237 | + when(run.getParent()).thenReturn(job); |
| 238 | + when(run.getAction(ParametersAction.class)).thenReturn( |
| 239 | + new ParametersAction(new StringParameterValue("test_key", "test_value")) |
| 240 | + ); |
| 241 | + when(job.getNextBuildNumber()).thenReturn(1); |
| 242 | + when(job.getName()).thenReturn("PR-1"); |
| 243 | + when(githubStatusChecksProperties.getRerunActionRole(job)).thenReturn("test-role"); |
| 244 | + when(githubStatusChecksProperties.isDisableRerunAction(job)).thenReturn(false); |
| 245 | + try(MockedStatic<User> staticUser = mockStatic(User.class)) { |
| 246 | + staticUser.when(() -> User.get("XiongKezhi")).thenReturn(user); |
| 247 | + when(user.getAuthorities()).thenReturn(userRoles); |
| 248 | + try (LogRecorder logRecorder = new LogRecorder().record(CheckRunGHEventSubscriber.class.getName(), Level.INFO).capture(1)) { |
| 249 | + new CheckRunGHEventSubscriber(jenkinsFacade, scmFacade, githubStatusChecksProperties) |
| 250 | + .onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR)); |
| 251 | + assertThat(logRecorder.getMessages()) |
| 252 | + .contains("The user XiongKezhi does not have the required test-role role for the rerun action on job codingstyle/PR-1"); |
| 253 | + } |
| 254 | + } |
| 255 | + } |
| 256 | + |
224 | 257 | @Test
|
225 | 258 | void shouldContainsUserAndBranchInShortDescriptionOfGitHubChecksRerunActionCause() {
|
226 | 259 | CheckRunGHEventSubscriber.GitHubChecksRerunActionCause cause =
|
|
0 commit comments