1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

Merge branch 'master' into jacocoCodeCoverage

This commit is contained in:
Christopher Fenner
2018-02-05 10:00:49 +01:00
committed by GitHub
16 changed files with 115 additions and 63 deletions

View File

@@ -11,3 +11,5 @@ indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.{yml,yaml}]
indent_size = 2

View File

@@ -11,3 +11,6 @@ cache:
- $HOME/.cache/pip
after_success:
- mvn -DrepoToken=$COVERALLS_REPO_TOKEN jacoco:report coveralls:report
notifications:
slack:
secure: UYzfd4QYLtAX39r8LzV1dYp7cKMhYRRjI/xswMEkR+RgdMWxVPPH3kcsNLwkdNGSPn1b8Aidz8YLss9JolrepWjwI283dK8EUthZAOw03+PmL5X/3nOJ7aGv0sxwYqF5ypltBrerTf6jtPUTcQdtao+0O8bgnzShc6nWWE4MLXonjOm1pZLRUo81un+0bzm8C2ABIeHC6xuZCRycXP5u1mW1nDLK3900uY1rxIDTSZKEzA0IzLQhE9uROvI1r48fW8cKJQQjMMO5PPorq+0eDl2YTE8rQr9ldvuRE7A/ubsOQR0N5F8iAv1JTZXuXGt62fw6eKDQ1h94suEk7X+baV0EwlfhsHXcI1MxRFwxNSr9k1WaVFfA4TrM8XYBAcW3JGRA51ZK3q4EcjpuxpupaA7kZDtH53W7ePzH2TIp6yknln1q+yfcsP7cGv38sSKpKwOyMgAPRElkZzcoo31kw/PLzKPXYJEovRqx/0lWzczbFSscsroNaGCavC02++bUnyUXW2W+PG4gDSBFVZjtrvTPKnZ6DpHXV97x6xC/CzyhFj/Nf+ao/J9IIfocnc4vXJojwS550KIvM7xCDJwa/+29dajj2l6dQqrcOe3UT3O5UGU9I0KkGEDMfkLOD71eRy58qiYz3y953e52DvvzWQJbvfuk8ubMO+Fmn4GyRz8=

View File

@@ -6,9 +6,8 @@ import org.junit.rules.RuleChain
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
@@ -20,9 +19,8 @@ class DockerExecuteTest extends BasePipelineTest {
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
.around(jlr)
.around(new JenkinsConfigRule(this))
public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this))
.around(jlr)
int whichDockerReturnValue = 0

View File

@@ -1,14 +1,17 @@
#!groovy
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Rule
import org.junit.Test
import util.JenkinsSetupRule
import static org.junit.Assert.assertTrue
import org.junit.rules.RuleChain
import util.Rules
class DurationMeasureTest extends BasePipelineTest {
@Rule
public JenkinsSetupRule setupRule = new JenkinsSetupRule(this)
public RuleChain rules = Rules.getCommonRules(this)
@Test
void testDurationMeasurement() throws Exception {

View File

@@ -6,7 +6,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.Rules
import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals
@@ -21,13 +21,11 @@ class InfluxWriteDataTest extends BasePipelineTest {
def cpe
public JenkinsSetupRule setupRule = new JenkinsSetupRule(this)
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain =
RuleChain.outerRule(setupRule)
.around(loggingRule)
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(loggingRule)
@Before
void init() throws Exception {

View File

@@ -10,10 +10,9 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
import util.Rules
public class MTABuildTest extends BasePipelineTest {
@@ -23,13 +22,12 @@ public class MTABuildTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public RuleChain ruleChain =
RuleChain.outerRule(thrown)
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(tmp)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
.around(new JenkinsConfigRule(this))
def currentDir
def otherDir
@@ -122,12 +120,13 @@ public class MTABuildTest extends BasePipelineTest {
binding.getVariable('env')['MTA_JAR_LOCATION'] = '/opt/mta'
def newDirName = 'newDir'
def newDir = new File("${currentDir}/${newDirName}")
def newDirPath = "${currentDir}/${newDirName}"
def newDir = new File(newDirPath)
newDir.mkdirs()
new File(newDir, 'mta.yaml') << defaultMtaYaml()
helper.registerAllowedMethod('pwd', [], { newDir } )
helper.registerAllowedMethod('pwd', [], { newDirPath } )
def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO')

View File

@@ -9,9 +9,8 @@ import com.lesfurets.jenkins.unit.BasePipelineTest
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
import util.Rules
class MavenExecuteTest extends BasePipelineTest {
@@ -20,9 +19,8 @@ class MavenExecuteTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
.around(jscr)
.around(new JenkinsConfigRule(this))
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(jscr)
def mavenExecuteScript
def cpe

View File

@@ -10,10 +10,10 @@ import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
import util.Rules
class NeoDeploymentTest extends BasePipelineTest {
@@ -23,12 +23,11 @@ class NeoDeploymentTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public RuleChain ruleChain = RuleChain.outerRule(thrown)
.around(tmp)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
.around(new JenkinsConfigRule(this))
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(tmp)
.around(jlr)
.around(jscr)
def workspacePath
def warArchiveName

View File

@@ -1,8 +1,4 @@
import hudson.AbortException
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import org.junit.rules.TemporaryFolder
import util.Rules
import com.lesfurets.jenkins.unit.BasePipelineTest
@@ -12,14 +8,15 @@ import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsReadYamlRule
class PipelineExecuteTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none()
@Rule
public RuleChain ruleChain = RuleChain.outerRule(thrown)
.around(new JenkinsSetupRule(this))
.around(new JenkinsConfigRule(this))
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
def pipelinePath
def checkoutParameters = [:]

View File

@@ -1,11 +1,12 @@
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.yaml.snakeyaml.Yaml
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsSetupRule
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
@@ -19,7 +20,7 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
def commonPipelineEnvironment
@Rule
public JenkinsSetupRule jsr = new JenkinsSetupRule(this)
public RuleChain rules = Rules.getCommonRules(this)
@Before
void init() {

View File

@@ -9,24 +9,21 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.Rules
class ToolValidateTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none()
private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsConfigRule jcr = new JenkinsConfigRule(this)
@Rule
public RuleChain ruleChain =
RuleChain.outerRule(tmp)
.around(thrown)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jcr)
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(tmp)
.around(thrown)
.around(jlr)
private notEmptyDir

View File

@@ -6,8 +6,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.Rules
import util.SharedLibraryCreator
import static org.hamcrest.Matchers.containsString
@@ -21,7 +20,7 @@ class UtilsTest extends BasePipelineTest {
public ExpectedException exception = ExpectedException.none()
@Rule
public JenkinsSetupRule setUpRule = new JenkinsSetupRule(this, SharedLibraryCreator.lazyLoadedLibrary)
public RuleChain rules = Rules.getCommonRules(this, SharedLibraryCreator.lazyLoadedLibrary)
Utils utils

View File

@@ -7,12 +7,12 @@ import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.yaml.snakeyaml.Yaml
class JenkinsConfigRule implements TestRule {
class JenkinsReadYamlRule implements TestRule {
final BasePipelineTest testInstance
JenkinsConfigRule(BasePipelineTest testInstance) {
JenkinsReadYamlRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
}
@@ -25,11 +25,15 @@ class JenkinsConfigRule implements TestRule {
return new Statement() {
@Override
void evaluate() throws Throwable {
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
Yaml yamlParser = new Yaml()
return yamlParser.load(parameters.text)
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map m ->
if(m.text) {
return new Yaml().load(m.text)
} else if(m.file) {
throw new UnsupportedOperationException()
} else {
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
}
})
DefaultValueCache.reset()
base.evaluate()
}

View File

@@ -0,0 +1,34 @@
package util
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
class JenkinsResetDefaultCacheRule implements TestRule {
JenkinsResetDefaultCacheRule() {
this(null)
}
//
// Actually not needed. Only provided for the sake of consistency
// with our other rules which comes with an constructor having the
// test case contained in the signature.
JenkinsResetDefaultCacheRule(BasePipelineTest testInstance) {
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
DefaultValueCache.reset()
base.evaluate()
}
}
}
}

View File

@@ -13,12 +13,13 @@ class JenkinsSetupRule implements TestRule {
final BasePipelineTest testInstance
JenkinsSetupRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
this(testInstance, null)
}
JenkinsSetupRule(BasePipelineTest testInstance, LibraryConfiguration configuration) {
this.testInstance = testInstance
this.library = configuration
if(configuration)
this.library = configuration
}
@Override

View File

@@ -0,0 +1,19 @@
package util;
import org.junit.rules.RuleChain;
import com.lesfurets.jenkins.unit.BasePipelineTest;
import com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration
public class Rules {
public static RuleChain getCommonRules(BasePipelineTest testCase) {
return getCommonRules(testCase, null)
}
public static RuleChain getCommonRules(BasePipelineTest testCase, LibraryConfiguration libConfig) {
return RuleChain.outerRule(new JenkinsSetupRule(testCase, libConfig))
.around(new JenkinsReadYamlRule(testCase))
.around(new JenkinsResetDefaultCacheRule())
}
}