2019-05-29 13:22:16 +02:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
import util.BasePiperTest
|
2020-01-15 13:16:25 +02:00
|
|
|
import util.JenkinsFileExistsRule
|
2020-01-28 14:22:37 +02:00
|
|
|
import util.JenkinsReadFileRule
|
2020-01-15 13:16:25 +02:00
|
|
|
import util.JenkinsWriteFileRule
|
2019-05-29 13:22:16 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.is
|
|
|
|
import static org.hamcrest.Matchers.hasItem
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
2020-01-28 14:22:37 +02:00
|
|
|
import org.junit.After
|
|
|
|
|
2019-05-29 13:22:16 +02:00
|
|
|
class CommonPipelineEnvironmentTest extends BasePiperTest {
|
|
|
|
|
2020-01-15 13:16:25 +02:00
|
|
|
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
|
|
|
private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule(this, [])
|
2020-01-28 14:22:37 +02:00
|
|
|
private JenkinsReadFileRule readFileRule = new JenkinsReadFileRule(this, null)
|
2020-01-15 13:16:25 +02:00
|
|
|
|
2019-05-29 13:22:16 +02:00
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
2020-01-15 13:16:25 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
|
|
|
.around(writeFileRule)
|
|
|
|
.around(fileExistsRule)
|
2020-01-28 14:22:37 +02:00
|
|
|
.around(readFileRule)
|
|
|
|
|
|
|
|
@After
|
|
|
|
void tearDown() {
|
|
|
|
nullScript.metaClass.findFiles = null
|
|
|
|
}
|
2019-05-29 13:22:16 +02:00
|
|
|
|
|
|
|
@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'))
|
|
|
|
}
|
2020-01-15 13:16:25 +02:00
|
|
|
|
2020-01-29 17:03:18 +02:00
|
|
|
@Test
|
|
|
|
void testContainereMap() {
|
|
|
|
nullScript.commonPipelineEnvironment.setContainerProperty('image', 'myImage')
|
|
|
|
assertThat(nullScript.commonPipelineEnvironment.getContainerProperty('image'), is('myImage'))
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:22:16 +02:00
|
|
|
}
|