Skip to content

Commit

Permalink
add unit test for getCheckouts()
Browse files Browse the repository at this point in the history
  • Loading branch information
car-roll committed Oct 31, 2019
1 parent 1ba50d1 commit 4693dc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jenkins.model.CauseOfInterruption;
import jenkins.model.Jenkins;
import jenkins.model.lazy.BuildReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import hudson.model.*;
import hudson.model.listeners.RunListener;
import hudson.model.queue.QueueTaskFuture;
import hudson.plugins.git.GitSCM;
import hudson.scm.SCM;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.security.Permission;
Expand All @@ -52,6 +54,8 @@
import jenkins.model.CauseOfInterruption;
import jenkins.model.InterruptedBuildAction;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSampleRepoRule;
import jenkins.plugins.git.GitStep;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Expand All @@ -60,6 +64,7 @@
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
Expand All @@ -86,6 +91,7 @@ public class WorkflowRunTest {
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();
@Rule public LoggerRule logging = new LoggerRule();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down Expand Up @@ -473,4 +479,17 @@ private void assertCulprits(WorkflowRun b, String... expectedIds) throws IOExcep
assertFalse(b.isLogUpdated());
}

@Test public void getScms() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "echo 'hello'");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--message=files");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "Jenkinsfile");
p.setDefinition(def);
WorkflowRun b = r.buildAndAssertSuccess(p);
List<SCM> checkouts = b.getCheckouts();
assertTrue(checkouts.size() == 1);
assertTrue(checkouts.get(0).getClass().getName().equals(GitSCM.class.getName()));
}
}

0 comments on commit 4693dc3

Please sign in to comment.