Skip to content

Commit

Permalink
Restore compatibility for GitSampleRepoRule (jenkinsci#1626)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MarkEWaite authored Aug 5, 2024
1 parent f87418a commit 29a5456
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/test/java/hudson/plugins/git/GitStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand All @@ -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."));
}

Expand All @@ -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"));
}

Expand All @@ -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"));
}

Expand Down
15 changes: 10 additions & 5 deletions src/test/java/jenkins/plugins/git/GitSampleRepoRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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();
Expand Down

0 comments on commit 29a5456

Please sign in to comment.