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

46 lines
1.3 KiB
Groovy
Raw Normal View History

package com.sap.piper
import org.jenkinsci.plugins.workflow.steps.MissingContextVariableException
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.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.Rules
import static org.hamcrest.Matchers.*
import static org.junit.Assert.assertThat
class JenkinsUtilsTest extends BasePiperTest {
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
2019-01-22 10:19:28 +02:00
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
2019-01-22 10:19:28 +02:00
.around(shellRule)
.around(loggingRule)
@Test
void testNodeAvailable() {
def result = jenkinsUtils.nodeAvailable()
2019-01-22 10:19:28 +02:00
assertThat(shellRule.shell, contains("echo 'Node is available!'"))
assertThat(result, is(true))
}
@Test
void testNoNodeAvailable() {
helper.registerAllowedMethod('sh', [String.class], {s ->
throw new MissingContextVariableException(String.class)
})
def result = jenkinsUtils.nodeAvailable()
assertThat(loggingRule.log, containsString('No node context available.'))
assertThat(result, is(false))
}
}