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/PiperTestBase.groovy

61 lines
1.6 KiB
Groovy
Raw Normal View History

2017-11-13 16:56:19 +02:00
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
import org.yaml.snakeyaml.Yaml
2017-11-13 16:56:19 +02:00
import static ProjectSource.projectSource
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import org.junit.Rule
import org.junit.rules.TemporaryFolder
2017-11-13 16:56:19 +02:00
public class PiperTestBase extends BasePipelineTest {
@Rule
public TemporaryFolder pipelineFolder = new TemporaryFolder()
private File pipeline
2017-11-14 12:08:42 +02:00
protected messages = [], shellCalls = []
2017-11-14 12:00:52 +02:00
2017-11-21 15:27:05 +02:00
void setUp() {
2017-11-14 12:00:52 +02:00
2017-11-13 16:56:19 +02:00
super.setUp()
2017-11-14 12:00:52 +02:00
messages.clear()
2017-11-14 12:08:42 +02:00
shellCalls.clear()
2017-11-14 12:00:52 +02:00
2017-11-13 16:56:19 +02:00
preparePiperLib()
2017-11-14 12:00:52 +02:00
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)} )
2017-11-14 12:08:42 +02:00
helper.registerAllowedMethod('sh', [String], { s ->
shellCalls.add(s.replaceAll(/\s+/, " ").trim())
})
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
Yaml yamlParser = new Yaml()
return yamlParser.load(parameters.text)
})
pipeline = pipelineFolder.newFile()
DefaultValueCache.reset()
}
protected withPipeline(p) {
2017-11-21 15:47:17 +02:00
pipeline << p
loadScript(pipeline.toURI().getPath())
2017-11-13 16:56:19 +02:00
}
private preparePiperLib() {
def piperLib = library()
.name('piper-library-os')
.retriever(projectSource())
.targetPath('clonePath/is/not/necessary')
.defaultVersion('<irrelevant>')
.allowOverride(true)
.implicit(false)
.build()
helper.registerSharedLibrary(piperLib)
}
}