mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
5f07490cf2
In case unstashAll is called with a Set containing a null value we get an ugly message in the log: Unstash failed: null (Could not instantiate {name=null} for UnstashStep(name: String): This can be avoided by unstashing only in case we have an ID.
82 lines
2.0 KiB
Groovy
82 lines
2.0 KiB
Groovy
package com.sap.piper
|
|
|
|
import org.junit.Rule
|
|
import org.junit.Before
|
|
import org.junit.Ignore
|
|
import org.junit.Test
|
|
import static org.junit.Assert.assertThat
|
|
import org.junit.rules.ExpectedException
|
|
import org.junit.rules.RuleChain
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
import static org.hamcrest.Matchers.hasItem
|
|
import static org.hamcrest.Matchers.is
|
|
import static org.hamcrest.Matchers.not
|
|
|
|
import util.JenkinsLoggingRule
|
|
import util.JenkinsShellCallRule
|
|
import util.BasePiperTest
|
|
import util.Rules
|
|
|
|
import com.sap.piper.Utils
|
|
|
|
class UtilsTest extends BasePiperTest {
|
|
private ExpectedException thrown = ExpectedException.none()
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
|
|
|
@Rule
|
|
public RuleChain rules = Rules
|
|
.getCommonRules(this)
|
|
.around(thrown)
|
|
.around(shellRule)
|
|
.around(loggingRule)
|
|
|
|
private parameters
|
|
|
|
@Before
|
|
void setup() {
|
|
|
|
parameters = [:]
|
|
|
|
}
|
|
|
|
@Test
|
|
void noValueGetMandatoryParameterTest() {
|
|
|
|
thrown.expect(Exception)
|
|
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR test")
|
|
|
|
utils.getMandatoryParameter(parameters, 'test', null)
|
|
}
|
|
|
|
@Test
|
|
void defaultValueGetMandatoryParameterTest() {
|
|
|
|
assert utils.getMandatoryParameter(parameters, 'test', 'default') == 'default'
|
|
}
|
|
|
|
@Test
|
|
void valueGetmandatoryParameterTest() {
|
|
|
|
parameters.put('test', 'value')
|
|
|
|
assert utils.getMandatoryParameter(parameters, 'test', null) == 'value'
|
|
}
|
|
|
|
@Test
|
|
void testGenerateSHA1() {
|
|
def result = utils.generateSha1('ContinuousDelivery')
|
|
// asserts
|
|
// generated with "echo -n 'ContinuousDelivery' | sha1sum | sed 's/ -//'"
|
|
assertThat(result, is('0dad6c33b6246702132454f604dee80740f399ad'))
|
|
}
|
|
|
|
@Test
|
|
void testUnstashAllSkipNull() {
|
|
|
|
def stashResult = utils.unstashAll(['a', null, 'b'])
|
|
assert stashResult == ['a', 'b']
|
|
}
|
|
}
|