Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from MarkEWaite/fix-submodule-url-regex
Fix submodule url regex [JENKINS-46054]
- Loading branch information
Showing
3 changed files
with
180 additions
and
2 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
110 changes: 110 additions & 0 deletions
110
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.jenkinsci.plugins.gitclient; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.*; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
|
||
public class SubmodulePatternStringTest { | ||
|
||
private Pattern submoduleConfigPattern; | ||
private String remoteName = "simple-name"; | ||
|
||
@Before | ||
public void configure() { | ||
// String patternString = "^submodule\\.([^ ]+)\\.url "; | ||
String patternString = CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING; | ||
submoduleConfigPattern = Pattern.compile(patternString, Pattern.MULTILINE); | ||
} | ||
|
||
@Issue("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)); | ||
} | ||
|
||
@Issue("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)); | ||
} | ||
|
||
@Issue("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); | ||
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find()); | ||
assertThat(matcher.group(1), is(remoteName)); | ||
} | ||
|
||
@Issue("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("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("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("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("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()); | ||
} | ||
} |