Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-14572] Add a test case for clone option's default 'fetch tag…
…s' behaviour Even with shallow clones "fetch all tags" is the default. Just added a missing test case and found a true/false bug in my previous commit which toggled the default to the not backwards compatible value.
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
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
58 changes: 58 additions & 0 deletions
58
src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.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,58 @@ | ||
package hudson.plugins.git.extensions.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import hudson.model.Result; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.plugins.git.TestGitRepo; | ||
import hudson.plugins.git.extensions.GitSCMExtensionTest; | ||
import hudson.plugins.git.extensions.GitSCMExtension; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
import org.jenkinsci.plugins.gitclient.Git; | ||
import org.jenkinsci.plugins.gitclient.GitClient; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Ronny Händel | ||
*/ | ||
public class CloneOptionShallowDefaultTagsTest extends GitSCMExtensionTest { | ||
|
||
FreeStyleProject project; | ||
TestGitRepo repo; | ||
|
||
@Override | ||
public void before() throws Exception { | ||
repo = new TestGitRepo("repo", tmp.newFolder(), listener); | ||
project = setupBasicProject(repo); | ||
} | ||
|
||
@Override | ||
protected GitSCMExtension getExtension() { | ||
final boolean shallowClone = true; | ||
final String noReference = null; | ||
final Integer noTimeout = null; | ||
return new CloneOption(shallowClone, noReference, noTimeout); | ||
} | ||
|
||
@Test | ||
public void evenShallowCloningFetchesTagsByDefault() throws Exception { | ||
final String tagName = "v0.0.1"; | ||
|
||
repo.commit("repo-init", repo.johnDoe, "repo0 initial commit"); | ||
repo.tag(tagName, "a tag that should be fetched by default"); | ||
|
||
assertTrue("scm polling should detect a change after initial commit", project.poll(listener).hasChanges()); | ||
|
||
build(project, Result.SUCCESS); | ||
|
||
assertEquals("tag " + tagName + " should have been cloned from remote", 1, tagsInProjectWorkspaceWithName(tagName).size()); | ||
} | ||
|
||
private Set<String> tagsInProjectWorkspaceWithName(String tagPattern) throws IOException, InterruptedException { | ||
GitClient git = Git.with(listener, null).in(project.getWorkspace()).getClient(); | ||
return git.getTagNames(tagPattern); | ||
} | ||
} |