Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Created a unit test that reproduces JENKINS-23179
  • Loading branch information
galbramc authored and MarkEWaite committed Aug 2, 2014
1 parent f214868 commit cecfd4f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/hudson/plugins/git/AbstractGitTestCase.java
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.Lists;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.*;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.CleanBeforeCheckout;
Expand Down Expand Up @@ -187,6 +189,19 @@ protected FreeStyleBuild build(final FreeStyleProject project, final String pare
}
return build;
}

protected MatrixBuild build(final MatrixProject project, final Result expectedResult, final String...expectedNewlyCommittedFiles) throws Exception {
final MatrixBuild build = project.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(build.getLog());
for(final String expectedNewlyCommittedFile : expectedNewlyCommittedFiles) {
assertTrue(expectedNewlyCommittedFile + " file not found in workspace", build.getWorkspace().child(expectedNewlyCommittedFile).exists());
}
if(expectedResult != null) {
assertBuildStatus(expectedResult, build);
}
return build;
}


protected EnvVars getEnvVars(FreeStyleProject project) {
for (hudson.tasks.Builder b : project.getBuilders()) {
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
@@ -1,8 +1,13 @@
package hudson.plugins.git;

import com.google.common.collect.Lists;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.*;
import hudson.plugins.git.GitSCM.BuildChooserContextImpl;
import hudson.plugins.git.browser.GitRepositoryBrowser;
Expand Down Expand Up @@ -985,6 +990,51 @@ public void testMergeFailedWithSlave() throws Exception {
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}


public void testMergeWithMatrixBuild() throws Exception {

MatrixProject project = createMatrixProject("xyz");
project.setAxes(new AxisList(new Axis("VAR","a","b")));

//FreeStyleProject project = setupSimpleProject("master");
//project.setAssignedLabel(createSlave().getSelfLabel());

GitSCM scm = new GitSCM(
createRemoteRepositories(),
Collections.singletonList(new BranchSpec("*")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
scm.getExtensions().add(new PreBuildMerge(new UserMergeOptions("origin", "integration", null)));
project.setScm(scm);

// create initial commit and then run the build against it:
commit("commitFileBase", johnDoe, "Initial Commit");
testRepo.git.branch("integration");
build(project, Result.SUCCESS, "commitFileBase");


testRepo.git.checkout(null, "topic1");
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit number 1");
final MatrixBuild build1 = build(project, Result.SUCCESS, commitFile1);
assertTrue(build1.getWorkspace().child(commitFile1).exists());

assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
// do what the GitPublisher would do
testRepo.git.deleteBranch("integration");
testRepo.git.checkout("topic1", "integration");

testRepo.git.checkout("master", "topic2");
final String commitFile2 = "commitFile2";
commit(commitFile2, johnDoe, "Commit number 2");
assertTrue("scm polling did not detect commit2 change", project.poll(listener).hasChanges());
final MatrixBuild build2 = build(project, Result.SUCCESS, commitFile2);
assertTrue(build2.getWorkspace().child(commitFile2).exists());
assertBuildStatusSuccess(build2);
assertFalse("scm polling should not detect any more changes after build", project.poll(listener).hasChanges());
}

public void testEnvironmentVariableExpansion() throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.setScm(new GitSCM("${CAT}"+testRepo.gitDir.getPath()));
Expand Down

0 comments on commit cecfd4f

Please sign in to comment.