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/EnvironmentUtilsTest.groovy

76 lines
2.0 KiB
Groovy
Raw Normal View History

2018-04-20 10:59:32 +02:00
package com.sap.piper
2018-03-09 18:58:11 +02:00
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsStepRule
2018-03-09 18:58:11 +02:00
import util.Rules
import hudson.AbortException
class EnvironmentUtilsTest extends BasePiperTest {
2018-03-09 18:58:11 +02:00
private ExpectedException thrown = new ExpectedException()
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(thrown)
2018-03-09 18:58:11 +02:00
@Test
void isEnvironmentVariableFailedTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> throw new AbortException('') })
thrown.expect(AbortException)
2018-04-10 18:23:44 +02:00
thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.")
2018-03-09 18:58:11 +02:00
EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
2018-03-09 18:58:11 +02:00
}
@Test
void isNotEnvironmentVariableTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> return '' })
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
2018-03-09 18:58:11 +02:00
assert isEnvVar == false
}
@Test
void isEnvironmentVariableTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' })
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
2018-03-09 18:58:11 +02:00
assert isEnvVar == true
}
@Test
void getEnvironmentVariableFailedTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> throw new AbortException('') })
thrown.expect(AbortException)
thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.")
EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME')
2018-03-09 18:58:11 +02:00
}
@Test
void getEnvironmentVariableTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' })
def envVar = EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME')
2018-03-09 18:58:11 +02:00
assert envVar == '/env/java'
}
}