mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
introduce JenkinsConfigRule
This commit is contained in:
parent
106a8b4693
commit
e8363e9637
@ -4,6 +4,7 @@ import org.junit.Rule
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.RuleChain
|
import org.junit.rules.RuleChain
|
||||||
|
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsLoggingRule
|
import util.JenkinsLoggingRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ class DockerExecuteTest extends PiperTestBase {
|
|||||||
@Rule
|
@Rule
|
||||||
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
||||||
.around(jlr)
|
.around(jlr)
|
||||||
|
.around(new JenkinsConfigRule(this))
|
||||||
|
|
||||||
int whichDockerReturnValue = 0
|
int whichDockerReturnValue = 0
|
||||||
|
|
||||||
@ -53,8 +55,8 @@ class DockerExecuteTest extends PiperTestBase {
|
|||||||
assertTrue(docker.getParameters().contains(' --volume my_vol:/my_vol'))
|
assertTrue(docker.getParameters().contains(' --volume my_vol:/my_vol'))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
|
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
|
||||||
|
|
||||||
whichDockerReturnValue = 1
|
whichDockerReturnValue = 1
|
||||||
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDockerWithParameters.groovy")
|
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDockerWithParameters.groovy")
|
||||||
|
@ -7,7 +7,7 @@ import org.junit.Test
|
|||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
import org.junit.rules.RuleChain
|
import org.junit.rules.RuleChain
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsLoggingRule
|
import util.JenkinsLoggingRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
import util.JenkinsShellCallRule
|
import util.JenkinsShellCallRule
|
||||||
@ -26,6 +26,7 @@ public class MTABuildTest extends PiperTestBase {
|
|||||||
.around(new JenkinsSetupRule(this))
|
.around(new JenkinsSetupRule(this))
|
||||||
.around(jlr)
|
.around(jlr)
|
||||||
.around(jscr)
|
.around(jscr)
|
||||||
|
.around(new JenkinsConfigRule(this))
|
||||||
|
|
||||||
def currentDir
|
def currentDir
|
||||||
def otherDir
|
def otherDir
|
||||||
|
@ -7,6 +7,7 @@ import org.junit.rules.RuleChain
|
|||||||
import static org.junit.Assert.assertEquals
|
import static org.junit.Assert.assertEquals
|
||||||
import static org.junit.Assert.assertTrue
|
import static org.junit.Assert.assertTrue
|
||||||
|
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
import util.JenkinsShellCallRule
|
import util.JenkinsShellCallRule
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ class MavenExecuteTest extends PiperTestBase {
|
|||||||
@Rule
|
@Rule
|
||||||
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
||||||
.around(jscr)
|
.around(jscr)
|
||||||
|
.around(new JenkinsConfigRule(this))
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
void init() {
|
void init() {
|
||||||
|
@ -6,6 +6,7 @@ import org.junit.Test
|
|||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
import org.junit.rules.RuleChain
|
import org.junit.rules.RuleChain
|
||||||
|
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsLoggingRule
|
import util.JenkinsLoggingRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
import util.JenkinsShellCallRule
|
import util.JenkinsShellCallRule
|
||||||
@ -23,6 +24,7 @@ class NeoDeploymentTest extends PiperTestBase {
|
|||||||
.around(new JenkinsSetupRule(this))
|
.around(new JenkinsSetupRule(this))
|
||||||
.around(jlr)
|
.around(jlr)
|
||||||
.around(jscr)
|
.around(jscr)
|
||||||
|
.around(new JenkinsConfigRule(this))
|
||||||
def archivePath
|
def archivePath
|
||||||
def warArchivePath
|
def warArchivePath
|
||||||
def propertiesFilePath
|
def propertiesFilePath
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import hudson.AbortException
|
import hudson.AbortException
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
|
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
@ -15,6 +16,7 @@ class PipelineExecuteTest extends PiperTestBase {
|
|||||||
@Rule
|
@Rule
|
||||||
public RuleChain ruleChain = RuleChain.outerRule(thrown)
|
public RuleChain ruleChain = RuleChain.outerRule(thrown)
|
||||||
.around(new JenkinsSetupRule(this))
|
.around(new JenkinsSetupRule(this))
|
||||||
|
.around(new JenkinsConfigRule(this))
|
||||||
|
|
||||||
def pipelinePath
|
def pipelinePath
|
||||||
def checkoutParameters = [:]
|
def checkoutParameters = [:]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||||
import com.sap.piper.DefaultValueCache
|
|
||||||
import org.yaml.snakeyaml.Yaml
|
import org.yaml.snakeyaml.Yaml
|
||||||
|
|
||||||
import static ProjectSource.projectSource
|
import static ProjectSource.projectSource
|
||||||
@ -19,14 +19,8 @@ public class PiperTestBase extends BasePipelineTest {
|
|||||||
|
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|
||||||
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
|
||||||
Yaml yamlParser = new Yaml()
|
|
||||||
return yamlParser.load(parameters.text)
|
|
||||||
})
|
|
||||||
|
|
||||||
pipeline = pipelineFolder.newFile()
|
pipeline = pipelineFolder.newFile()
|
||||||
|
|
||||||
DefaultValueCache.reset()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected withPipeline(p) {
|
protected withPipeline(p) {
|
||||||
|
@ -7,6 +7,7 @@ import org.junit.rules.ExpectedException
|
|||||||
import org.junit.rules.RuleChain
|
import org.junit.rules.RuleChain
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
|
|
||||||
|
import util.JenkinsConfigRule
|
||||||
import util.JenkinsLoggingRule
|
import util.JenkinsLoggingRule
|
||||||
import util.JenkinsSetupRule
|
import util.JenkinsSetupRule
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ class ToolValidateTest extends PiperTestBase {
|
|||||||
private ExpectedException thrown = new ExpectedException().none()
|
private ExpectedException thrown = new ExpectedException().none()
|
||||||
private TemporaryFolder tmp = new TemporaryFolder()
|
private TemporaryFolder tmp = new TemporaryFolder()
|
||||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||||
|
private JenkinsConfigRule jcr = new JenkinsConfigRule(this)
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public RuleChain ruleChain =
|
public RuleChain ruleChain =
|
||||||
@ -22,6 +24,7 @@ class ToolValidateTest extends PiperTestBase {
|
|||||||
.around(thrown)
|
.around(thrown)
|
||||||
.around(new JenkinsSetupRule(this))
|
.around(new JenkinsSetupRule(this))
|
||||||
.around(jlr)
|
.around(jlr)
|
||||||
|
.around(jcr)
|
||||||
|
|
||||||
private notEmptyDir
|
private notEmptyDir
|
||||||
private script
|
private script
|
||||||
|
38
test/groovy/util/JenkinsConfigRule.groovy
Normal file
38
test/groovy/util/JenkinsConfigRule.groovy
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||||
|
import com.sap.piper.DefaultValueCache
|
||||||
|
import org.junit.rules.TestRule
|
||||||
|
import org.junit.runner.Description
|
||||||
|
import org.junit.runners.model.Statement
|
||||||
|
import org.yaml.snakeyaml.Yaml
|
||||||
|
|
||||||
|
class JenkinsConfigRule implements TestRule {
|
||||||
|
|
||||||
|
final BasePipelineTest testInstance
|
||||||
|
|
||||||
|
|
||||||
|
JenkinsConfigRule(BasePipelineTest testInstance) {
|
||||||
|
this.testInstance = testInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Statement apply(Statement base, Description description) {
|
||||||
|
return statement(base)
|
||||||
|
}
|
||||||
|
|
||||||
|
private Statement statement(final Statement base) {
|
||||||
|
return new Statement() {
|
||||||
|
@Override
|
||||||
|
void evaluate() throws Throwable {
|
||||||
|
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
||||||
|
Yaml yamlParser = new Yaml()
|
||||||
|
return yamlParser.load(parameters.text)
|
||||||
|
})
|
||||||
|
DefaultValueCache.reset()
|
||||||
|
|
||||||
|
base.evaluate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user