forked from kckane/dynamic-axis-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-27243] - Added Unit test for the issue
The commit also adds a test of the basic functionality Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
- Loading branch information
1 parent
bde53b7
commit 229a41c
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/test/java/ca/silvermaplesolutions/jenkins/plugins/daxis/DynamicAxisTest.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,73 @@ | ||
package ca.silvermaplesolutions.jenkins.plugins.daxis; | ||
|
||
import hudson.matrix.Axis; | ||
import hudson.matrix.MatrixBuild; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.ParametersDefinitionProperty; | ||
import hudson.model.StringParameterDefinition; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Bug; | ||
import org.jvnet.hudson.test.FakeChangeLogSCM; | ||
import org.jvnet.hudson.test.HudsonTestCase; | ||
|
||
/** | ||
* Tests for {@link DynamicAxis}. | ||
* @author Oleg Nenashev <o.v.nenashev@gmail.com> | ||
*/ | ||
public class DynamicAxisTest extends HudsonTestCase { | ||
|
||
MatrixProject p; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
p = createMatrixProject(); | ||
p.getAxes().add(new DynamicAxis("AXIS", "AXIS_VALUES")); | ||
} | ||
|
||
public @Test void testDefaultInjection() throws Exception { | ||
p.addProperty(new ParametersDefinitionProperty( | ||
new StringParameterDefinition("AXIS_VALUES", "1 2 3"))); | ||
|
||
MatrixBuild run = buildAndAssertSuccess(p); | ||
assertEquals(3, run.getExactRuns().size()); | ||
} | ||
|
||
/** | ||
* Runs the test, when an environment contributor uses axis values | ||
* to build the environment. | ||
* @see AxisValuesUserSCM | ||
*/ | ||
@Bug(27243) | ||
public @Test void testInjectionWithAxisValuesUser() throws Exception { | ||
p.addProperty(new ParametersDefinitionProperty( | ||
new StringParameterDefinition("AXIS_VALUES", "1 2 3"))); | ||
|
||
// Inject SCM, which implicitly triggers axes rebuild | ||
p.setScm(new AxisValuesUserSCM()); | ||
|
||
final MatrixBuild run = buildAndAssertSuccess(p); | ||
|
||
// No additional values have been injected | ||
assertEquals(3, run.getExactRuns().size()); | ||
} | ||
|
||
/** | ||
* Just a stub {@link SCM}, which rebuilds axes list. | ||
*/ | ||
public static class AxisValuesUserSCM extends FakeChangeLogSCM { | ||
|
||
@Override | ||
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) { | ||
if (build instanceof MatrixBuild) { | ||
final MatrixProject prj = (MatrixProject) build.getParent(); | ||
for (Axis axis : prj.getAxes()) { | ||
// Get values for a opeeration | ||
axis.getValues(); | ||
} | ||
} | ||
} | ||
} | ||
} |