I am trying to test this code:
vars/checkconfig.groovy
import com.pipeline.CheckConfig
def call(def map) {
CheckConfig checkConfig = new CheckConfig(this);
checkConfig.run(map);
}
com/pipeline/CheckConfig.groovy
class CheckConfig implements Serializable {
def script
CheckConfig(script) {
this.script = script
}
void run(def configMap) {
script.wrap([$class: 'BuildUser']) {
script.properties([script.buildDiscarder(script.logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '2'))])
if (script.currentBuild.buildCauses.shortDescription.contains("Branch indexing")) {
script.currentBuild.result = BuildStatus.ABORTED
script.error("Aborting build from branch indexing. Nothing to be built by any user or webhook (git push)")
}
}
setUpPipeline(configMap)
new BuildNotification(script).notifyBuild(BuildStatus.STARTED)
}
....
}
And my test:
class CheckConfigTest extends BasePipelineTest{
// Before every testcase is run, do this:
@Before
void setUp() {
scriptRoots += 'vars'
super.setUp()
}
@Test
void 'Check config command'() {
//helper.registerAllowedMethod("wrap", [Map.class], {m->return m})
def script = loadScript('vars/checkConfig.groovy')
script.call([:])
printCallStack()
}
}
It is throwing the following error:
groovy.lang.MissingMethodException: No signature of method: checkConfig.wrap() is applicable for argument types: (LinkedHashMap, com.avoristravel.pipeline.CheckConfig$_run_closure1) values: [[$class:BuildUser], com.avoristravel.pipeline.CheckConfig$_run_closure1@780c39e3]
Possible solutions: grep(), wait(), run(), run(), dump(), grep(java.lang.Object)
Is it possible to mock the wrap method from the build user vars plugin?
Aucun commentaire:
Enregistrer un commentaire