Open
Description
Hi,
Given is the pipeline which contains function inside the simpleDeclarativePipeline.pipeline file:
pipeline {
agent { node { label 'test1' } }
stages {
stage('sdfsdf') {
steps {
githubNotify status: 'PENDING', context: 'Pipeline'
runFunc()
}
}
}
}
def runFunc(){
echo "inside runFunc"
doSomeStuff()
}
When runFunc is mocked:
void setUp() throws Exception {
baseScriptRoot = 'unit-testing-jenkinsfile'
scriptRoots += 'src/main/groovy'
scriptExtension = 'pipeline'
super.setUp()
helper.registerAllowedMethod("runFunc")
helper.registerAllowedMethod("githubNotify", [Map.class], null)
}
@Test
void should_execute_without_errors() throws Exception {
def script = runScript("simpleDeclarativePipeline.pipeline")
printCallStack()
assertJobStatusSuccess()
}
Then mocked function is not executed but real one instead and thus exception is thrown:
groovy.lang.MissingMethodException: No signature of method: simpleDeclarativePipeline.doSomeStuff() is applicable for argument types: () values: []
When runFunc inside pipeline is deleted:
pipeline {
agent { node { label 'test1' } }
stages {
stage('sdfsdf') {
steps {
githubNotify status: 'PENDING', context: 'Pipeline'
runFunc()
}
}
}
}
Then runFunc is mocked as expected.
I tried newest version of JenkinsPipelineUnit: 1.13
This is a problem for me as I have very rich local functions I want to mock during pipeline testing. I do not want to mock functions like doSomeStuff in the example.
If this is a bug - do you know any workaround for this issue ?
Metadata
Assignees
Labels
No labels
Activity