1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/com/sap/piper/PrerequisitesTest.groovy

72 lines
1.7 KiB
Groovy
Raw Normal View History

package com.sap.piper
import util.JenkinsLoggingRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import hudson.AbortException
import util.BasePiperTest
import util.Rules
class PrerequisitesTest extends BasePiperTest {
2018-10-31 09:03:47 +02:00
def result = 'SUCCESS'
@Rule
public ExpectedException thrown = ExpectedException.none()
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(loggingRule)
@Before
public void init() {
2018-10-31 09:03:47 +02:00
nullScript.currentBuild = [
'setResult' : { r -> result = r },
STEP_NAME: 'dummy',
]
nullScript.STEP_NAME = 'dummy'
}
@Test
public void checkScriptProvidedTest() {
def script = Prerequisites.checkScript(nullScript, [script:{}])
assert script != null
2018-10-31 09:03:47 +02:00
assert result == 'SUCCESS'
}
@Test
public void checkScriptMissingTest() {
loggingRule.expect('No reference to surrounding script provided with key \'script\'')
def script = Prerequisites.checkScript(nullScript, [:])
assert script == null
2018-10-31 09:03:47 +02:00
assert result == 'UNSTABLE'
}
@Test
public void checkScriptMissingTestFeatureFlagSet() {
thrown.expect(AbortException)
thrown.expectMessage('No reference to surrounding script provided')
try {
System.setProperty('com.sap.piper.featureFlag.failOnMissingScript', 'true')
Prerequisites.checkScript(nullScript, [:])
} finally {
System.clearProperty('com.sap.piper.featureFlag.failOnMissingScript')
}
}
}