mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Fix merging if default values do not exist (#130)
This commit is contained in:
parent
3d5a97ab71
commit
540e8c36db
@ -10,6 +10,8 @@ class ConfigurationMerger {
|
||||
Map filteredConfig = configKeys?configs.subMap(configKeys):configs
|
||||
Map merged = [:]
|
||||
|
||||
defaults = defaults ?: [:]
|
||||
|
||||
merged.putAll(defaults)
|
||||
|
||||
for(String key : filteredConfig.keySet())
|
||||
|
@ -50,19 +50,30 @@ class ConfigurationMergerTest {
|
||||
|
||||
@Test
|
||||
void testMergeDeepStructure(){
|
||||
Map defaults = [fruits: [apples: 1, oranges: 10, bananaaas: 0]]
|
||||
Map configuration = [fruits: [bananaaas: 50, cucumbers: 1000]]
|
||||
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.bananaaas)
|
||||
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)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReadConfigInsideMerge() {
|
||||
DefaultValueCache.createInstance([steps:[myStep:[overwrite: 'x', defaultKey1:'defaultValue1']]])
|
||||
|
Loading…
Reference in New Issue
Block a user