Skip to content
Permalink
Browse files

Verify specific revision chooser used if revision is passed

Verifies fix for mistake in pull request 350: if you are configuring
some extensions, like clean before checkout for example, you still want
to ensure that

node {
  checkout scm
}

in a multibranch pipeline project checks out the same revision as
Jenkinsfile itself.
  • Loading branch information...
MarkEWaite committed Sep 17, 2016
1 parent d7d56b2 commit e15a431a62781c6081c57354a33a7e148a4452a1
Showing with 38 additions and 1 deletion.
  1. +38 −1 src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java
@@ -1,9 +1,18 @@
package jenkins.plugins.git;

import hudson.model.TaskListener;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.BuildChooserSetting;
import hudson.plugins.git.extensions.impl.LocalBranch;
import hudson.util.StreamTaskListener;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import static org.hamcrest.Matchers.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
@@ -20,7 +29,7 @@
public JenkinsRule r = new JenkinsRule();
@Rule
public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

// TODO AbstractGitSCMSourceRetrieveHeadsTest *sounds* like it would be the right place, but it does not in fact retrieve any heads!
@Issue("JENKINS-37482")
@Test
@@ -81,4 +90,32 @@ public void pruneRemovesDeletedBranches() throws Exception {
/* Fetch and confirm dev branch was pruned */
assertEquals("[SCMHead{'dev2'}, SCMHead{'master'}]", source.fetch(listener).toString());
}

@Test
public void testSpecificRevisionBuildChooser() throws Exception {
sampleRepo.init();

/* Write a file to the master branch */
sampleRepo.write("master-file", "master-content-" + UUID.randomUUID().toString());
sampleRepo.git("add", "master-file");
sampleRepo.git("commit", "--message=master-branch-commit-message");

/* Fetch from sampleRepo */
GitSCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true);
List<GitSCMExtension> extensions = new ArrayList<GitSCMExtension>();
assertThat(source.getExtensions(), is(empty()));
LocalBranch localBranchExtension = new LocalBranch("**");
extensions.add(localBranchExtension);
source.setExtensions(extensions);
assertEquals(source.getExtensions(), extensions);
TaskListener listener = StreamTaskListener.fromStderr();

/* Check that BuildChooserSetting has been added to extensions by build() */
SCMHead head = new SCMHead("master");
SCMRevision revision = new AbstractGitSCMSource.SCMRevisionImpl(head, "beaded4deed2bed4feed2deaf78933d0f97a5a34");
GitSCM scm = (GitSCM) source.build(head, revision);
assertEquals(extensions.get(0), scm.getExtensions().get(0));
assertTrue(scm.getExtensions().get(1) instanceof BuildChooserSetting);
assertEquals(2, scm.getExtensions().size());
}
}

0 comments on commit e15a431

Please sign in to comment.
You can’t perform that action at this time.