Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added test case for JENKINS-40255
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.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,45 @@ | ||
package org.jenkinsci.plugins.workflow.job; | ||
|
||
|
||
import hudson.model.Result; | ||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class WorkflowJobTest { | ||
@Rule public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Issue("JENKINS-40255") | ||
@Test public void getSCM() throws Exception { | ||
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); | ||
p.setDefinition(new CpsFlowDefinition( | ||
"node {\n" + | ||
" checkout(new hudson.scm.NullSCM())\n" + | ||
"}")); | ||
assertTrue("No runs has been performed and there should be no SCMs", p.getSCMs().isEmpty()); | ||
|
||
p.scheduleBuild2(0); | ||
j.waitUntilNoActivity(); | ||
|
||
assertEquals("Expecting one SCM",1, p.getSCMs().size()); | ||
|
||
p.setDefinition(new CpsFlowDefinition("error 'Fail!'")); | ||
p.scheduleBuild2(0); | ||
j.waitUntilNoActivity(); | ||
|
||
assertEquals("Last run should have failed", Result.FAILURE, p.getLastBuild().getResult()); | ||
assertEquals("Expecting one SCM even though last run failed",1, p.getSCMs().size()); | ||
|
||
p.setDefinition(new CpsFlowDefinition("echo 'Pass!'")); | ||
p.scheduleBuild2(0); | ||
j.waitUntilNoActivity(); | ||
|
||
assertEquals("Last run should have succeeded", Result.SUCCESS, p.getLastBuild().getResult()); | ||
assertEquals("Expecting zero SCMs",0, p.getSCMs().size()); | ||
} | ||
} |