Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add [JENKINS-46054] failing tests
If the repository URL for a submodule includes ".url" in the URL, then the submodule query code in the command line git implementation gathers the wrong name as the name of the submodule. These tests check specific conditions with the regular expression string used to parse the "git config" output. They intentionally fail with the current regular expression.
- Loading branch information
1 parent
c2b1ff4
commit 725a9ac
Showing
2 changed files
with
115 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
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()); | ||
} | ||
} |