mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Merge remote-tracking branch 'github/master' into HEAD
This commit is contained in:
commit
87f899a731
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -468,4 +467,31 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
warAction: 'illegalWARAction',
|
||||
vmSize: 'lite')
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployHostProvidedAsDeprecatedParameterTest() {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
deployHost: "my.deploy.host.com"
|
||||
)
|
||||
|
||||
assert jlr.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.")
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployAccountProvidedAsDeprecatedParameterTest() {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
host: "my.deploy.host.com",
|
||||
deployAccount: "myAccount"
|
||||
)
|
||||
|
||||
assert jlr.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.")
|
||||
}
|
||||
}
|
||||
|
@ -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 = [:]
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
}
|
34
test/groovy/util/JenkinsResetDefaultCacheRule.groovy
Normal file
34
test/groovy/util/JenkinsResetDefaultCacheRule.groovy
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
19
test/groovy/util/Rules.groovy
Normal file
19
test/groovy/util/Rules.groovy
Normal 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())
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ def call(parameters = [:]) {
|
||||
'applicationName',
|
||||
'archivePath',
|
||||
'account',
|
||||
'deployAccount', //deprecated, replaced by parameter 'account'
|
||||
'deployHost', //deprecated, replaced by parameter 'host'
|
||||
'deployMode',
|
||||
'dockerEnvVars',
|
||||
'dockerImage',
|
||||
@ -60,14 +62,21 @@ def call(parameters = [:]) {
|
||||
stepConfiguration.put('account', defaultDeployAccount)
|
||||
}
|
||||
|
||||
if(parameters.DEPLOY_HOST && !parameters.host) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'DEPLOY_HOST' is used. This will not work anymore in future versions. Use parameter 'host' instead."
|
||||
parameters.put('host', parameters.DEPLOY_HOST)
|
||||
if(parameters.deployHost && !parameters.host) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead."
|
||||
parameters.put('host', parameters.deployHost)
|
||||
}
|
||||
|
||||
if(parameters.CI_DEPLOY_ACCOUNT && !parameters.account) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'CI_DEPLOY_ACCOUNT' is used. This will not work anymore in future versions. Use parameter 'account' instead."
|
||||
parameters.put('account', parameters.CI_DEPLOY_ACCOUNT)
|
||||
if(parameters.deployAccount && !parameters.account) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead."
|
||||
parameters.put('account', parameters.deployAccount)
|
||||
}
|
||||
|
||||
def credId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId')
|
||||
|
||||
if(credId && !parameters.neoCredentialsId) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions."
|
||||
parameters.put('neoCredentialsId', credId)
|
||||
}
|
||||
|
||||
// Backward compatibility end
|
||||
|
Loading…
x
Reference in New Issue
Block a user