mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
add further test case
This commit is contained in:
parent
394aaa6577
commit
b891b36fbf
@ -1,12 +1,12 @@
|
||||
package com.sap.piper.mta
|
||||
|
||||
class MtaMultiplexer implements Serializable {
|
||||
static def createJobs(Script step, Map parameters, List excludeList, String jobPrefix, String buildDescriptorFile, String scanType, Closure worker) {
|
||||
def jobs = [:]
|
||||
static Map createJobs(Script step, Map parameters, List excludeList, String jobPrefix, String buildDescriptorFile, String scanType, Closure worker) {
|
||||
Map jobs = [:]
|
||||
def filesToScan
|
||||
|
||||
filesToScan = step.findFiles(glob: "**${File.separator}${buildDescriptorFile}")
|
||||
step.echo "Found ${filesToScan.length} ${scanType} descriptor files"
|
||||
step.echo "Found ${filesToScan.length} ${scanType} descriptor files!"
|
||||
filesToScan = removeExcludedFiles(step, filesToScan, excludeList)
|
||||
|
||||
for (String file : filesToScan){
|
||||
@ -14,9 +14,7 @@ class MtaMultiplexer implements Serializable {
|
||||
options.putAll(parameters)
|
||||
options.scanType = scanType
|
||||
options.buildDescriptorFile = file
|
||||
jobs.put("${jobPrefix} - ${file.replace("${File.separator}${buildDescriptorFile}",'')}", {
|
||||
worker(options)
|
||||
})
|
||||
jobs["${jobPrefix} - ${file.replace("${File.separator}${buildDescriptorFile}",'')}"] = {worker(options)}
|
||||
}
|
||||
return jobs
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package com.sap.piper.mta
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem
|
||||
import static org.hamcrest.Matchers.hasKey
|
||||
import static org.hamcrest.Matchers.hasSize
|
||||
import static org.hamcrest.Matchers.hasEntry
|
||||
import static org.hamcrest.Matchers.not
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.hamcrest.Matchers.containsString
|
||||
|
||||
import static org.junit.Assert.assertThat
|
||||
import org.junit.Rule
|
||||
@ -40,4 +44,34 @@ class MtaMultiplexerTest extends BasePiperTest {
|
||||
assertThat(result, hasSize(3))
|
||||
assertThat(jlr.log, containsString('Skipping pom.xml'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateJobs() {
|
||||
def optionsList = []
|
||||
// prepare test data
|
||||
helper.registerAllowedMethod("findFiles", [Map.class], { map ->
|
||||
if (map.glob == '**/pom.xml') {
|
||||
return [new File('some-service/pom.xml'), new File('some-other-service/pom.xml')].toArray()
|
||||
}
|
||||
if (map.glob == '**/package.json') {
|
||||
return [new File('some-ui/package.json'), new File('somer-service-broker/package.json')].toArray()
|
||||
}
|
||||
})
|
||||
// execute test
|
||||
def result = MtaMultiplexer.createJobs(nullScript, ['myParameters':'value'], [], 'TestJobs', 'pom.xml', 'maven'){
|
||||
options -> optionsList.push(options)
|
||||
}
|
||||
// invoke jobs
|
||||
for(Closure c : result.values()) c()
|
||||
// asserts
|
||||
assertThat(result.size(), is(2))
|
||||
assertThat(result, hasKey('TestJobs - some-other-service'))
|
||||
assertThat(jlr.log, containsString('Found 2 maven descriptor files!'))
|
||||
assertThat(optionsList.get(0), hasEntry('myParameters', 'value'))
|
||||
assertThat(optionsList.get(0), hasEntry('scanType', 'maven'))
|
||||
assertThat(optionsList.get(0), hasEntry('buildDescriptorFile', 'some-service/pom.xml'))
|
||||
assertThat(optionsList.get(1), hasEntry('myParameters', 'value'))
|
||||
assertThat(optionsList.get(1), hasEntry('scanType', 'maven'))
|
||||
assertThat(optionsList.get(1), hasEntry('buildDescriptorFile', 'some-other-service/pom.xml'))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user