From 29a5456289b2d8ae73726839075b9283094c1265 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sun, 4 Aug 2024 20:16:34 -0600 Subject: [PATCH] Restore compatibility for GitSampleRepoRule (#1626) * Restore compatibility for GitSampleRepoRule I forgot that there are other consumers of the Git plugin test suite. Plugin BOM automated tests detected the problem. * Remove code repetition introduced by prior commit --- src/test/java/hudson/plugins/git/GitStepTest.java | 8 ++++---- .../jenkins/plugins/git/GitSampleRepoRule.java | 15 ++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitStepTest.java b/src/test/java/hudson/plugins/git/GitStepTest.java index a5322cdfde..8eef466b23 100644 --- a/src/test/java/hudson/plugins/git/GitStepTest.java +++ b/src/test/java/hudson/plugins/git/GitStepTest.java @@ -328,7 +328,7 @@ private WorkflowJob createJob() throws Exception { public void testDoNotifyCommitWithInvalidApiToken() throws Exception { assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable()); createJob(); - String response = sampleRepo.notifyCommit(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN); + String response = sampleRepo.notifyCommitWithResults(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN); assertThat(response, containsString("Invalid access token")); } @@ -337,7 +337,7 @@ public void testDoNotifyCommitWithInvalidApiToken() throws Exception { public void testDoNotifyCommitWithAllowModeRandomValue() throws Exception { assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable()); createJob(); - String response = sampleRepo.notifyCommit(r, null); + String response = sampleRepo.notifyCommitWithResults(r, null); assertThat(response, containsString("An access token is required. Please refer to Git plugin documentation (https://plugins.jenkins.io/git/#plugin-content-push-notification-from-repository) for details.")); } @@ -349,7 +349,7 @@ public void testDoNotifyCommitWithSha1AndAllowModePollWithInvalidToken() throws createJob(); /* sha1 is ignored because invalid access token is provided */ String sha1 = "4b714b66959463a98e9dfb1983db5a39a39fa6d6"; - String response = sampleRepo.notifyCommit(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN, sha1); + String response = sampleRepo.notifyCommitWithResults(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN, sha1); assertThat(response, containsString("Invalid access token")); } @@ -361,7 +361,7 @@ public void testDoNotifyCommitWithSha1AndAllowModePoll() throws Exception { createJob(); /* sha1 is ignored because no access token is provided */ String sha1 = "4b714b66959463a98e9dfb1983db5a39a39fa6d6"; - String response = sampleRepo.notifyCommit(r, null, sha1); + String response = sampleRepo.notifyCommitWithResults(r, null, sha1); assertThat(response, containsString("An access token is required when using the sha1 parameter")); } diff --git a/src/test/java/jenkins/plugins/git/GitSampleRepoRule.java b/src/test/java/jenkins/plugins/git/GitSampleRepoRule.java index 152169719c..504035f59d 100644 --- a/src/test/java/jenkins/plugins/git/GitSampleRepoRule.java +++ b/src/test/java/jenkins/plugins/git/GitSampleRepoRule.java @@ -101,13 +101,18 @@ public final boolean mkdirs(String rel) throws IOException { return new File(this.sampleRepo, rel).mkdirs(); } - public String notifyCommit(JenkinsRule r) throws Exception { + public void notifyCommit(JenkinsRule r) throws Exception { String notifyCommitToken = ApiTokenPropertyConfiguration.get().generateApiToken("notifyCommit").getString("value"); - return notifyCommit(r, notifyCommitToken, null); + notifyCommitWithResults(r, notifyCommitToken, null); } - public String notifyCommit(JenkinsRule r, @CheckForNull String notifyCommitToken) throws Exception { - return notifyCommit(r, notifyCommitToken, null); + public String notifyCommitWithResults(JenkinsRule r) throws Exception { + String notifyCommitToken = ApiTokenPropertyConfiguration.get().generateApiToken("notifyCommit").getString("value"); + return notifyCommitWithResults(r, notifyCommitToken, null); + } + + public String notifyCommitWithResults(JenkinsRule r, @CheckForNull String notifyCommitToken) throws Exception { + return notifyCommitWithResults(r, notifyCommitToken, null); } /** @@ -126,7 +131,7 @@ public String notifyCommit(JenkinsRule r, @CheckForNull String notifyCommitToken * @param notifyCommitToken token used for notifyCommit authentication * @param sha1 SHA-1 hash to included in notifyCommit **/ - public String notifyCommit(JenkinsRule r, @CheckForNull String notifyCommitToken, @CheckForNull String sha1) throws Exception { + public String notifyCommitWithResults(JenkinsRule r, @CheckForNull String notifyCommitToken, @CheckForNull String sha1) throws Exception { boolean expectError = notifyCommitToken == null || notifyCommitToken.contains(INVALID_NOTIFY_COMMIT_TOKEN); synchronousPolling(r); JenkinsRule.WebClient webClient = r.createWebClient();