Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore compatibility for GitSampleRepoRule #1626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading