jenkinsci / JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
MIT License
1.55k stars 396 forks source link

register allowed method which accept a Gstring #45

Closed mioyn closed 7 years ago

mioyn commented 7 years ago

Following is the testcase using spock

def "test pipeline"() {
    setup:
    ....

    helper.registerAllowedMethod("node", [String.class, Closure.class], null)
    helper.registerAllowedMethod("node", [Closure.class], null)
    addEnvVar('workerLabel','testworker')
    when:
       loadScript('Jenkinsfile')
    then:
    println helper
}

my jenkinsfile having a node method with Gstring.

node("${env.workerLabel}") {
        if ((someProperties != null) && (anotherProperties != null)) {
            getEnvironmentsBuildNumbers(someProperties, anotherProperties)
        }
        logParser()
   }

while executing the testcase am getting MissingMethodException.

   groovy.lang.MissingMethodException: No signature of method: jenkinspipeline.node() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, jenkinspipeline$_call_closure2) values: [testworker, jenkinspipeline$_call_closure2@6d6bc158]
   Possible solutions: notify(), wait(), run(), call(), run(), any()
ozangunalp commented 7 years ago

Well I've been trying to reproduce this, but I can't.

If you can't find a way and it persist, I suggest you to open a PR with a failing test.

Thanks.