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/ConfigurationMergerTest.groovy
Christopher Fenner 6007f54074
use new config handler in steps (#253)
* use new config handler

* use new config handler

* add reporting

* Update checksPublishResults.groovy

* remove unused ConfigurationMerger methods

* fix typo

* revert changes on script loading

* remove outdated test case

* Add missing import
2018-08-15 11:53:28 +02:00

64 lines
2.4 KiB
Groovy

package com.sap.piper
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsResetDefaultCacheRule
class ConfigurationMergerTest {
@Rule
public JenkinsResetDefaultCacheRule resetDefaultValueCacheRule = new JenkinsResetDefaultCacheRule()
@Test
void testMerge(){
Map defaults = [dockerImage: 'mvn']
Map parameters = [goals: 'install', flags: '']
Set parameterKeys = ['flags']
Map configuration = [flags: '-B']
Set configurationKeys = ['flags']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
Assert.assertEquals('mvn', merged.dockerImage)
Assert.assertNull(merged.goals)
Assert.assertEquals('', merged.flags)
}
@Test
void testMergeParameterWithDefault(){
Map defaults = [nonErpDestinations: []]
Map parameters = [nonErpDestinations: null]
Set parameterKeys = ['nonErpDestinations']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, defaults)
Assert.assertEquals([], merged.nonErpDestinations)
}
@Test
void testMergeDeepStructure(){
Map defaults = [fruits: [apples: 1, oranges: 10, bananas: 0]]
Map configuration = [fruits: [bananas: 50, cucumbers: 1000]]
Set configurationKeys = ['fruits']
Map parameters = [fruits: [apples: 18], veggie: []]
Set parameterKeys = ['fruits']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
Assert.assertEquals(50, merged.fruits.bananas)
Assert.assertEquals(18, merged.fruits.apples)
Assert.assertEquals(10, merged.fruits.oranges)
Assert.assertEquals(1000, merged.fruits.cucumbers)
Assert.assertEquals(null, merged.veggie)
}
@Test
void testMergeDeepStructureWithMissingDefaults(){
Map defaults = [others:[apples: 18]]
Map configuration = [fruits: [bananas: 50, cucumbers: 1000]]
Set configurationKeys = ['fruits']
Map merged = ConfigurationMerger.merge(configuration, configurationKeys, defaults)
Assert.assertEquals(50, merged.fruits.bananas)
Assert.assertEquals(18, merged.others.apples)
Assert.assertEquals(1000, merged.fruits.cucumbers)
}
}