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

RealJenkinsRule should not overwrite JenkinsLocationConfiguration if otherwise set #512

Merged

Conversation

jglick
Copy link
Member

@jglick jglick commented Nov 11, 2022

For example you may wish to test behavior of Jenkins behind a reverse proxy and define a particular root URL explicitly.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

I don't suppose test coverage for this could be trivially added with e.g.

diff --git a/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java b/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java
index 6471f85..d437f57 100644
--- a/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java
+++ b/src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java
@@ -60,6 +60,7 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import jenkins.model.Jenkins;
+import jenkins.model.JenkinsLocationConfiguration;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.hamcrest.core.IsNull;
@@ -201,6 +202,17 @@ public class RealJenkinsRuleTest {
         assertNull(Stapler.getCurrentRequest());
     }
 
+    @Test public void stepsDoNotOverwriteJenkinsLocationConfigurationIfOtherwiseSet() throws Throwable {
+        rr.then(RealJenkinsRuleTest::_stepsDoNotOverwriteJenkinsLocationConfigurationIfOtherwiseSet1);
+        rr.then(RealJenkinsRuleTest::_stepsDoNotOverwriteJenkinsLocationConfigurationIfOtherwiseSet2);
+    }
+    private static void _stepsDoNotOverwriteJenkinsLocationConfigurationIfOtherwiseSet1(JenkinsRule r) throws Throwable {
+        assertNotNull(JenkinsLocationConfiguration.get().getUrl());
+        JenkinsLocationConfiguration.get().setUrl("https://example.com/");
+    }
+    private static void _stepsDoNotOverwriteJenkinsLocationConfigurationIfOtherwiseSet2(JenkinsRule r) throws Throwable {
+        assertEquals("https://example.com/", JenkinsLocationConfiguration.get().getUrl());
+    }
 
     @Test
     public void test500Errors() throws IOException {

@jglick
Copy link
Member Author

jglick commented Nov 14, 2022

Yes, something along those lines should work for test coverage, will try it when I get a chance.

@jglick jglick merged commit 035693a into jenkinsci:master Nov 18, 2022
@jglick jglick deleted the RealJenkinsRule-JenkinsLocationConfiguration branch November 18, 2022 15:50
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.

3 participants