2018-10-18 08:51:48 +02:00
|
|
|
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 {
|
2019-01-22 10:22:15 +02:00
|
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2019-01-22 10:19:28 +02:00
|
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2018-10-18 08:51:48 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
2019-01-22 10:19:28 +02:00
|
|
|
.around(shellRule)
|
2019-01-22 10:22:15 +02:00
|
|
|
.around(loggingRule)
|
2018-10-18 08:51:48 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testNodeAvailable() {
|
|
|
|
def result = jenkinsUtils.nodeAvailable()
|
2019-01-22 10:19:28 +02:00
|
|
|
assertThat(shellRule.shell, contains("echo 'Node is available!'"))
|
2018-10-18 08:51:48 +02:00
|
|
|
assertThat(result, is(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testNoNodeAvailable() {
|
|
|
|
helper.registerAllowedMethod('sh', [String.class], {s ->
|
|
|
|
throw new MissingContextVariableException(String.class)
|
|
|
|
})
|
|
|
|
|
|
|
|
def result = jenkinsUtils.nodeAvailable()
|
2019-01-22 10:22:15 +02:00
|
|
|
assertThat(loggingRule.log, containsString('No node context available.'))
|
2018-10-18 08:51:48 +02:00
|
|
|
assertThat(result, is(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|