Skip to content

Commit 1798e21

Browse files
committed
fix: can't delete GitHub Enterprise servers
add a test for GitHubConfiguration
1 parent a7d01ea commit 1798e21

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public GitHubConfiguration() {
5959

6060
@Override
6161
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
62+
setEndpoints(null);
6263
req.bindJSON(this, json);
6364
return true;
6465
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.jenkinsci.plugins.github_branch_source;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.hasSize;
5+
import static org.hamcrest.Matchers.is;
6+
7+
import java.util.List;
8+
import org.htmlunit.html.HtmlForm;
9+
import org.htmlunit.html.HtmlInput;
10+
import org.junit.Before;
11+
import org.junit.Rule;
12+
import org.junit.Test;
13+
import org.jvnet.hudson.test.JenkinsRule;
14+
15+
public class GitHubConfigurationTest {
16+
17+
@Rule
18+
public final JenkinsRule j = new JenkinsRule();
19+
20+
private GitHubConfiguration globalConfig;
21+
22+
@Before
23+
public void setUp() {
24+
globalConfig = GitHubConfiguration.all().getInstance(GitHubConfiguration.class);
25+
}
26+
27+
@Test
28+
public void configRoundTripTestNoChanges() throws Exception {
29+
globalConfig.addEndpoint(new Endpoint("https://www.example.com/api/v3", "example.com"));
30+
List<Endpoint> endpoints = globalConfig.getEndpoints();
31+
assertThat(endpoints, is(hasSize(1)));
32+
Endpoint endpoint = endpoints.get(0);
33+
assertThat(endpoint.getApiUri(), is("https://www.example.com/api/v3"));
34+
assertThat(endpoint.getName(), is("example.com"));
35+
36+
// Submit the global configuration page with no changes
37+
j.configRoundtrip();
38+
39+
endpoints = globalConfig.getEndpoints();
40+
assertThat(endpoints, is(hasSize(1)));
41+
endpoint = endpoints.get(0);
42+
assertThat(endpoint.getApiUri(), is("https://www.example.com/api/v3"));
43+
assertThat(endpoint.getName(), is("example.com"));
44+
}
45+
46+
@Test
47+
public void configDeleteEndpoint() throws Exception {
48+
globalConfig.addEndpoint(new Endpoint("https://www.example.com/api/v3", "example.com"));
49+
List<Endpoint> endpoints = globalConfig.getEndpoints();
50+
assertThat(endpoints, is(hasSize(1)));
51+
52+
j.configRoundtrip();
53+
54+
// delete the endpoint in the UI
55+
HtmlForm config = j.createWebClient().goTo("configure").getFormByName("config");
56+
HtmlInput input = config.getInputByName("_.apiUri");
57+
input.getParentNode().removeChild(input);
58+
input = config.getInputByName("_.name");
59+
input.getParentNode().removeChild(input);
60+
j.submit(config);
61+
62+
// there should be no endpoints now
63+
endpoints = globalConfig.getEndpoints();
64+
assertThat(endpoints, is(hasSize(0)));
65+
}
66+
}

0 commit comments

Comments
 (0)