2017-11-13 16:56:19 +02:00
|
|
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
2017-12-06 13:03:06 +02:00
|
|
|
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
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.rules.TemporaryFolder
|
|
|
|
|
2017-11-13 16:56:19 +02:00
|
|
|
public class PiperTestBase extends BasePipelineTest {
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
@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())
|
|
|
|
})
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
|
|
|
Yaml yamlParser = new Yaml()
|
|
|
|
return yamlParser.load(parameters.text)
|
|
|
|
})
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
pipeline = pipelineFolder.newFile()
|
2017-12-06 13:03:06 +02:00
|
|
|
|
|
|
|
DefaultValueCache.reset()
|
2017-11-14 13:57:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected withPipeline(p) {
|
2017-11-21 15:47:17 +02:00
|
|
|
pipeline << p
|
2017-11-16 14:47:00 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|