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/CommonPipelineEnvironmentTest.groovy
Kevin Stiehl d1c8abc6b3
refactor: move common pipeline environment handling to golang (#2823)
* make use of new read,writePipelineEnv Steps in groovy

* remove unused cat

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-06-15 14:34:56 +02:00

61 lines
2.1 KiB
Groovy

import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsFileExistsRule
import util.JenkinsReadFileRule
import util.JenkinsWriteFileRule
import util.JenkinsReadYamlRule
import util.Rules
import static org.hamcrest.CoreMatchers.is
import static org.hamcrest.Matchers.hasItem
import static org.junit.Assert.assertThat
import org.junit.After
class CommonPipelineEnvironmentTest extends BasePiperTest {
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule(this, [])
private JenkinsReadFileRule readFileRule = new JenkinsReadFileRule(this, null)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
.around(writeFileRule)
.around(fileExistsRule)
.around(readFileRule)
@After
void tearDown() {
nullScript.metaClass.findFiles = null
}
@Test
void testCustomValueList() {
nullScript.commonPipelineEnvironment.setValue('myList', [])
nullScript.commonPipelineEnvironment.getValue('myList').add('item1')
nullScript.commonPipelineEnvironment.getValue('myList').add('item2')
assertThat(nullScript.commonPipelineEnvironment.getValue('myList'), hasItem('item1'))
assertThat(nullScript.commonPipelineEnvironment.getValue('myList'), hasItem('item2'))
}
@Test
void testCustomValueMap() {
nullScript.commonPipelineEnvironment.setValue('myList', [:])
nullScript.commonPipelineEnvironment.getValue('myList').key1 = 'val1'
nullScript.commonPipelineEnvironment.getValue('myList').key2 = 'val2'
assertThat(nullScript.commonPipelineEnvironment.getValue('myList').key1, is('val1'))
assertThat(nullScript.commonPipelineEnvironment.getValue('myList').key2, is('val2'))
}
@Test
void testContainereMap() {
nullScript.commonPipelineEnvironment.setContainerProperty('image', 'myImage')
assertThat(nullScript.commonPipelineEnvironment.getContainerProperty('image'), is('myImage'))
}
}