Skip to content

fix: can't delete GitHub Enterprise servers #400

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public GitHubConfiguration() {

@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
setEndpoints(null);
req.bindJSON(this, json);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jenkinsci.plugins.github_branch_source;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

import java.util.List;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlInput;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class GitHubConfigurationTest {

@Rule
public final JenkinsRule j = new JenkinsRule();

private GitHubConfiguration globalConfig;

@Before
public void setUp() {
globalConfig = GitHubConfiguration.all().getInstance(GitHubConfiguration.class);
}

@Test
public void configRoundTripTestNoChanges() throws Exception {
globalConfig.addEndpoint(new Endpoint("https://www.example.com/api/v3", "example.com"));
List<Endpoint> endpoints = globalConfig.getEndpoints();
assertThat(endpoints, is(hasSize(1)));
Endpoint endpoint = endpoints.get(0);
assertThat(endpoint.getApiUri(), is("https://www.example.com/api/v3"));
assertThat(endpoint.getName(), is("example.com"));

// Submit the global configuration page with no changes
j.configRoundtrip();

endpoints = globalConfig.getEndpoints();
assertThat(endpoints, is(hasSize(1)));
endpoint = endpoints.get(0);
assertThat(endpoint.getApiUri(), is("https://www.example.com/api/v3"));
assertThat(endpoint.getName(), is("example.com"));
}

@Test
public void configDeleteEndpoint() throws Exception {
globalConfig.addEndpoint(new Endpoint("https://www.example.com/api/v3", "example.com"));
List<Endpoint> endpoints = globalConfig.getEndpoints();
assertThat(endpoints, is(hasSize(1)));

j.configRoundtrip();

// delete the endpoint in the UI
HtmlForm config = j.createWebClient().goTo("configure").getFormByName("config");
HtmlInput input = config.getInputByName("_.apiUri");
input.getParentNode().removeChild(input);
input = config.getInputByName("_.name");
input.getParentNode().removeChild(input);
j.submit(config);

// there should be no endpoints now
endpoints = globalConfig.getEndpoints();
assertThat(endpoints, is(hasSize(0)));
}
}