-
Notifications
You must be signed in to change notification settings - Fork 381
/
SubmodulePatternStringTest.java
88 lines (81 loc) · 3.08 KB
/
SubmodulePatternStringTest.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.jenkinsci.plugins.gitclient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.jvnet.hudson.test.Issue;
@RunWith(Parameterized.class)
public class SubmodulePatternStringTest {
private final String remoteName;
private final String submoduleConfigOutput;
private final Matcher matcher;
private static final Pattern SUBMODULE_CONFIG_PATTERN = Pattern.compile(CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING, Pattern.MULTILINE);
public SubmodulePatternStringTest(String repoUrl, String remoteName)
{
this.remoteName = remoteName;
this.submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
this.matcher = SUBMODULE_CONFIG_PATTERN.matcher(submoduleConfigOutput);
}
/*
* Permutations of repository URLs and remote names with various
* protocols and remote names, permuted with various suffixes.
*
* Tests file, ssh (both forms), git, and https.
*/
@Parameterized.Parameters(name = "{0}-{1}")
public static Collection<Object[]> repoAndRemote() {
List<Object[]> arguments = new ArrayList<>();
String[] repoUrls = {
"file://gitroot/thirdparty.url.repo",
"git://gitroot/repo",
"git@github.com:jenkinsci/JENKINS-46054",
"https://github.com/MarkEWaite/JENKINS-46054",
"https://mark.url:some%20pass.urlify@gitroot/repo",
"ssh://git.example.com/MarkEWaite/JENKINS-46054",
// JENKINS-56175 notes that submodule URL's with spaces don't
// work in the git plugin. This test shows they don't work at
// one level. Other levels also have failures.
// "file://gitroot/has space",
};
String[] remoteNames = {
"has space",
"has.url space",
"simple",
"simple.name",
"simple.url.name",
"url",
"modules/module.named.url"
};
String [] suffixes = {
"",
".git",
".url",
".url.git",
".git.url",
};
for (String repoUrlParam : repoUrls) {
for (String repoUrlSuffix : suffixes) {
for (String remoteNameParam : remoteNames) {
for (String remoteNameSuffix : suffixes) {
Object[] item = {repoUrlParam + repoUrlSuffix, remoteNameParam + remoteNameSuffix};
arguments.add(item);
}
}
}
}
return arguments;
}
@Issue("JENKINS-46054")
@Test
public void urlFoundInSubmoduleConfigOutput() {
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}
}