Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from MarkEWaite/master-PRxxx-honor-checkout-t…
…imeout [JENKINS-22547] Honor checkout timeout setting
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 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
103 changes: 103 additions & 0 deletions
103
src/test/java/hudson/plugins/git/extensions/impl/CheckoutOptionTest.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,103 @@ | ||
package hudson.plugins.git.extensions.impl; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.git.BranchSpec; | ||
import hudson.plugins.git.GitException; | ||
import hudson.plugins.git.GitSCM; | ||
import hudson.plugins.git.GitTool; | ||
import hudson.plugins.git.SubmoduleConfig; | ||
import hudson.plugins.git.UserRemoteConfig; | ||
import hudson.plugins.git.extensions.GitSCMExtension; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.jenkinsci.plugins.gitclient.CheckoutCommand; | ||
import org.jenkinsci.plugins.gitclient.Git; | ||
import org.jenkinsci.plugins.gitclient.GitClient; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class CheckoutOptionTest { | ||
|
||
private CheckoutOption option; | ||
private static final int INITIAL_TIMEOUT = 10; | ||
|
||
public CheckoutOptionTest() { | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
option = new CheckoutOption(INITIAL_TIMEOUT); | ||
} | ||
|
||
@Test | ||
public void testGetTimeout() { | ||
assertEquals(INITIAL_TIMEOUT, (int) option.getTimeout()); | ||
} | ||
|
||
@Test | ||
public void testRequiresWorkspaceForPolling() { | ||
assertFalse(option.requiresWorkspaceForPolling()); | ||
} | ||
|
||
@Test | ||
public void testDecorateCheckoutCommand() throws Exception { | ||
final int NEW_TIMEOUT = 13; | ||
|
||
CheckoutCommandImpl cmd = new CheckoutCommandImpl(); | ||
assertEquals(INITIAL_TIMEOUT, cmd.getTimeout()); | ||
|
||
GitSCM scm = null; | ||
Run build = null; | ||
TaskListener listener = null; | ||
GitClient git = null; | ||
|
||
option = new CheckoutOption(NEW_TIMEOUT); | ||
option.decorateCheckoutCommand(scm, build, git, listener, cmd); | ||
assertEquals(NEW_TIMEOUT, cmd.getTimeout()); | ||
} | ||
|
||
public class CheckoutCommandImpl implements CheckoutCommand { | ||
|
||
private int timeout = INITIAL_TIMEOUT; | ||
|
||
public int getTimeout() { | ||
return timeout; | ||
} | ||
|
||
@Override | ||
public CheckoutCommand timeout(Integer timeout) { | ||
this.timeout = timeout; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CheckoutCommand ref(String ref) { | ||
throw new UnsupportedOperationException("Don't call me"); | ||
} | ||
|
||
@Override | ||
public CheckoutCommand branch(String branch) { | ||
throw new UnsupportedOperationException("Don't call me"); | ||
} | ||
|
||
@Override | ||
public CheckoutCommand deleteBranchIfExist(boolean deleteBranch) { | ||
throw new UnsupportedOperationException("Don't call me"); | ||
} | ||
|
||
@Override | ||
public CheckoutCommand sparseCheckoutPaths(List<String> sparseCheckoutPaths) { | ||
throw new UnsupportedOperationException("Don't call me"); | ||
} | ||
|
||
@Override | ||
public void execute() throws GitException, InterruptedException { | ||
throw new UnsupportedOperationException("Don't call me"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/hudson/plugins/git/extensions/impl/CheckoutOptionWorkflowTest.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,32 @@ | ||
package hudson.plugins.git.extensions.impl; | ||
|
||
import jenkins.plugins.git.GitSampleRepoRule; | ||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class CheckoutOptionWorkflowTest { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
@Rule | ||
public GitSampleRepoRule sampleRepo = new GitSampleRepoRule(); | ||
|
||
@Test | ||
public void checkoutTimeout() throws Exception { | ||
sampleRepo.init(); | ||
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); | ||
p.setDefinition(new CpsFlowDefinition( | ||
"node {\n" | ||
+ " checkout(\n" | ||
+ " [$class: 'GitSCM', extensions: [[$class: 'CheckoutOption', timeout: 1234]],\n" | ||
+ " userRemoteConfigs: [[url: $/" + sampleRepo + "/$]]]\n" | ||
+ " )" | ||
+ "}")); | ||
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
r.assertLogContains("# timeout=1234", b); | ||
} | ||
} |