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

58 lines
2.3 KiB
Groovy
Raw Normal View History

package com.sap.piper
import org.junit.Assert
import org.junit.Test
class ConfigurationMergerTest {
@Test
void testMerge(){
Map defaults = [dockerImage: 'mvn']
Map parameters = [goals: 'install', flags: '']
List parameterKeys = ['flags']
Map configuration = [flags: '-B']
List 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]
List parameterKeys = ['nonErpDestinations']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, defaults)
Assert.assertEquals([], merged.nonErpDestinations)
}
@Test
void testMergeCustomPipelineValues(){
Map defaults = [dockerImage: 'mvn']
Map parameters = [goals: 'install', flags: '']
List parameterKeys = ['flags']
Map configuration = [flags: '-B']
List configurationKeys = ['flags']
Map pipelineDataMap = [artifactVersion: '1.2.3', flags: 'test']
Map merged = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, configuration, configurationKeys, defaults)
Assert.assertEquals('', merged.flags)
Assert.assertEquals('1.2.3', merged.artifactVersion)
}
@Test
void testMergeDeepStructure(){
Map defaults = [fruits: [apples: 1, oranges: 10, bananaaas: 0]]
Map configuration = [fruits: [bananaaas: 50, cucumbers: 1000]]
2018-02-07 13:01:46 +02:00
List configurationKeys = ['fruits']
Map parameters = [fruits: [apples: 18], veggie: []]
List parameterKeys = ['fruits']
2018-02-05 21:31:30 +02:00
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
Assert.assertEquals(50, merged.fruits.bananaaas)
Assert.assertEquals(18, merged.fruits.apples)
2018-02-05 20:54:04 +02:00
Assert.assertEquals(10, merged.fruits.oranges)
2018-02-07 13:01:46 +02:00
Assert.assertEquals(1000, merged.fruits.cucumbers)
Assert.assertEquals(null, merged.veggie)
}
}