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

Add support for custom prefix #924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vlatombe
Copy link
Member

Fixes #917

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@Vlatombe Vlatombe requested a review from jglick February 21, 2025 15:35
Copy link
Member

@daniel-beck daniel-beck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! (Untested.)


@Test public void noPrefix() throws Throwable {
rr.noPrefix().startJenkins();
assertThat(rr.getUrl().getPath(), emptyString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be equalTo("/")?

@@ -825,7 +859,7 @@ public URL getUrl() throws MalformedURLException {
if (port == 0) {
throw new IllegalStateException("This method must be called after calling #startJenkins.");
}
return new URL(https ? "https" : "http", host, port, "/jenkins/");
return new URL(https ? "https" : "http", host, port, prefix == null ? "" : prefix + "/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new URL(https ? "https" : "http", host, port, prefix == null ? "" : prefix + "/");
return new URL(https ? "https" : "http", host, port, prefix == null ? "/" : prefix + "/");

Comment on lines +413 to +416
var sanitized = Util.fixEmpty(prefix);
if (sanitized == null) {
throw new IllegalStateException("Use noPrefix() to remove the prefix.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my mind it would be clearer to delete noPrefix and just let .withPrefix("") mean to request http://localhost:12345/ which would be consistent with .withPrefix("/xxx") meaning http://localhost:12345/xxx/. The root URL is always expected to end with a slash.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent treatment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow specifying custom context path in RealJenkinsRule
3 participants