-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathGitLabHookCreatorParameterizedTest.java
More file actions
64 lines (56 loc) · 2.53 KB
/
GitLabHookCreatorParameterizedTest.java
File metadata and controls
64 lines (56 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.jenkins.plugins.gitlabbranchsource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.Is.is;
import io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer;
import java.util.Arrays;
import jenkins.model.JenkinsLocationConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
@WithJenkins
class GitLabHookCreatorParameterizedTest {
private static JenkinsRule r;
@BeforeAll
static void setUp(JenkinsRule rule) {
r = rule;
}
static Object[][] data() {
return new Object[][] {
{"intranet.local:8080", false, "/gitlab-systemhook/post"},
{"intranet.local", true, "/gitlab-webhook/post"},
{"www.mydomain.com:8000", true, "/gitlab-webhook/post"},
{"www.mydomain.com", false, "/gitlab-systemhook/post"},
{"www.mydomain.com/jenkins", true, "/gitlab-webhook/post"}
};
}
@ParameterizedTest
@MethodSource("data")
void hookUrl(String jenkinsUrl, boolean hookType, String expectedPath) {
Arrays.asList("http://", "https://").forEach(proto -> {
String expected = proto + jenkinsUrl + expectedPath;
JenkinsLocationConfiguration.get().setUrl(proto + jenkinsUrl);
String hookUrl = GitLabHookCreator.getHookUrl(null, hookType);
GitLabHookCreator.checkURL(hookUrl);
assertThat(hookUrl.replaceAll(proto, ""), not(containsString("//")));
assertThat(hookUrl, is(expected));
});
}
@ParameterizedTest
@MethodSource("data")
void hookUrlFromCustomRootUrl(String jenkinsUrl, boolean hookType, String expectedPath) {
Arrays.asList("http://", "https://").forEach(proto -> {
String expected = proto + jenkinsUrl + expectedPath;
JenkinsLocationConfiguration.get().setUrl("http://whatever");
GitLabServer server = new GitLabServer("https://gitlab.com", "GitLab", null);
server.setHooksRootUrl(proto + jenkinsUrl);
String hookUrl = GitLabHookCreator.getHookUrl(server, hookType);
GitLabHookCreator.checkURL(hookUrl);
assertThat(hookUrl.replaceAll(proto, ""), not(containsString("//")));
assertThat(hookUrl, is(expected));
});
}
}