Skip to content

Commit

Permalink
Added test for JENKINS-29796
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Aug 6, 2015
1 parent 054359b commit e67c39c
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/test/java/hudson/plugins/git/SCMTriggerTest.java
Expand Up @@ -33,6 +33,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.TemporaryDirectoryAllocator;

public abstract class SCMTriggerTest extends AbstractGitProject
Expand Down Expand Up @@ -224,13 +225,37 @@ public void testCommitAsBranchSpec() throws Exception {
"detached");
}


public void check(ZipFile repoZip, Properties commits, String branchSpec,
@Issue("JENKINS-29796")
@Test
public void testMultipleRefspecs() throws Exception {
final String remote = prepareRepo(namespaceRepoZip);
final UserRemoteConfig remoteConfig = new UserRemoteConfig(remote, "origin",
"+refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*", null);
// First, build the master branch
String branchSpec = "refs/heads/master";
FreeStyleProject project = setupProject(asList(remoteConfig),
asList(new BranchSpec(branchSpec)),
//empty scmTriggerSpec, SCMTrigger triggered manually
"", isDisableRemotePoll(), getGitClient());
triggerSCMTrigger(project.getTrigger(SCMTrigger.class));
FreeStyleBuild build1 = waitForBuildFinished(project, 1, 60000);
assertNotNull("Job has not been triggered", build1);

// Now switch request a different branch
GitSCM scm = (GitSCM) project.getScm();
scm.getBranches().set(0,new BranchSpec("b_namespace3/master"));
TaskListener listener = StreamTaskListener.fromStderr();

// Since the new branch has an additional commit, polling should report changes. Without the fix for
// JENKINS-29796, this assertion fails.
PollingResult poll = project.poll(listener);
assertEquals("Expected and actual polling results disagree", true, poll.hasChanges());
}

public void check(ZipFile repoZip, Properties commits, String branchSpec,
String expected_GIT_COMMIT, String expected_GIT_BRANCH) throws Exception {
File tempRemoteDir = tempAllocator.allocate();
extract(repoZip, tempRemoteDir);
final String remote = tempRemoteDir.getAbsolutePath();

String remote = prepareRepo(repoZip);

FreeStyleProject project = setupProject(asList(new UserRemoteConfig(remote, null, null, null)),
asList(new BranchSpec(branchSpec)),
//empty scmTriggerSpec, SCMTrigger triggered manually
Expand All @@ -257,7 +282,13 @@ public void check(ZipFile repoZip, Properties commits, String branchSpec,
assertEquals("Unexpected GIT_BRANCH",
expected_GIT_BRANCH, build1.getEnvironment(null).get("GIT_BRANCH"));
}


private String prepareRepo(ZipFile repoZip) throws IOException {
File tempRemoteDir = tempAllocator.allocate();
extract(repoZip, tempRemoteDir);
return tempRemoteDir.getAbsolutePath();
}

private Future<Void> triggerSCMTrigger(final SCMTrigger trigger)
{
if(trigger == null) return null;
Expand Down

0 comments on commit e67c39c

Please sign in to comment.