Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix both JENKINS-48818 and JENKINS-46054
Add JENKINS-48818 test - space character in submodule remote name Submodule remote name which contains a space character was supported by git client plugin versions prior to 2.7.0. The bug fix for JENKINS-46054 (support submodule update when the remote name or the remote URL end with '.url') broke support for submodule remote names which contain a space. This includes a test to show that a remote name containing a space character is not correctly handled by the 2.7.0 change.
- Loading branch information
1 parent
2df89c5
commit 6929755
Showing
3 changed files
with
74 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 58 additions & 87 deletions
145
src/test/java/org/jenkinsci/plugins/gitclient/SubmodulePatternStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,81 @@ | ||
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.Matchers.is; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
import org.junit.Before; | ||
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 Pattern submoduleConfigPattern; | ||
private String remoteName = "simple-name"; | ||
private final String remoteName; | ||
private final String submoduleConfigOutput; | ||
private final Matcher matcher; | ||
|
||
@Before | ||
public void configure() { | ||
// String patternString = "^submodule\\.([^ ]+)\\.url "; | ||
String patternString = CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING; | ||
submoduleConfigPattern = Pattern.compile(patternString, Pattern.MULTILINE); | ||
} | ||
private static final Pattern SUBMODULE_CONFIG_PATTERN = Pattern.compile(CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING, Pattern.MULTILINE); | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlEmbeddedInRepoURL() { | ||
String repoUrl = "file://gitroot/thirdparty.url.repo.git"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
public SubmodulePatternStringTest(String repoUrl, String remoteName) | ||
{ | ||
this.remoteName = remoteName; | ||
this.submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
this.matcher = SUBMODULE_CONFIG_PATTERN.matcher(submoduleConfigOutput); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlEmbeddedInRepoURLsubmoduleEmbeddedDot() { | ||
String repoUrl = "https://mark.url:some%20pass.urlify@gitroot/repo.git"; | ||
remoteName = "simple.name"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
/* | ||
* 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 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", | ||
}; | ||
String[] remoteNames = { | ||
"has space", | ||
"has.url space", | ||
"simple", | ||
"simple.name", | ||
"simple.url.name", | ||
}; | ||
String [] suffixes = { | ||
"", | ||
".git", | ||
".url", | ||
".url.git", | ||
}; | ||
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 urlEmbeddedInSubmoduleRepoNameEndsWithURL() { | ||
String repoUrl = "https://gitroot/repo.url"; | ||
remoteName = "simple.name"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
public void urlFoundInSubmoduleConfigOutput() { | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlEmbeddedInSubmoduleRepoNameEndsWithURLSpace() { | ||
String repoUrl = "https://gitroot/repo.url "; | ||
remoteName = "simple.name"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlEmbeddedInSubmoduleNameAndRepoNameEndsWithURL() { | ||
String repoUrl = "https://gitroot/repo.url.git"; | ||
remoteName = "simple.name.url"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlExploratoryTestFailureCase() { | ||
/* See https://github.com/MarkEWaite/JENKINS-46054.url/ */ | ||
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url"; | ||
remoteName = "modules/JENKINS-46504.url"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void remoteNameIncludesSubmodule() { | ||
/* See https://github.com/MarkEWaite/JENKINS-46054.url/ */ | ||
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url"; | ||
remoteName = "submodule.JENKINS-46504.url"; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("JENKINS-46054") | ||
@Test | ||
public void urlEmbeddedInRepoNameEndsWithURLEmptyRemoteName() { | ||
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url.git"; | ||
remoteName = ""; | ||
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl; | ||
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput); | ||
assertFalse("Unexpected match found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
} | ||
} |