I'm trying to write a unit test for a util function in a Jenkins shared library. The util function, calls the Office365Connector
plugin in Jenkins.
My util function looks like this:
#!/usr/bin/env groovy
import pe.ui.BuildNotificationSettings
import pe.ui.BuildStates
def call(BuildNotificationSettings options, BuildStates status) {
options.teamsChannelWebhookUrlList.each {
office365ConnectorSend (
status: status.toString(),
webhookUrl: "$it",
color: BuildStates.valueOf(status.toString()).color,
message: "Build ${status.toString()}: ${JOB_NAME} - ${BUILD_DISPLAY_NAME}<br>Pipeline duration: ${currentBuild.durationString}"
)
}
}
The use case that I'm trying to test is that the office365ConnectorSend
function is called.
I've tried the following approach:
import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification
import pe.ui.BuildNotificationSettings
import pe.ui.BuildStates
public class _sendTeamsMessageSpec extends JenkinsPipelineSpecification {
def _sendTeamsMessage = null
def setup() {
_sendTeamsMessage = loadPipelineScriptForTest("vars/_sendTeamsMessage.groovy")
def office365ConnectorSend = Mock(office365ConnectorSend)
}
def "returns without sending no build notification settings are passed" () {
given:
def options = new BuildNotificationSettings(
shouldSendNotification: null,
teamsChannelWebhookUrlList: null
)
when:
def result = _sendTeamsMessage(options, null)
then:
0 * explicitlyMockPipelineVariable("office365ConnectorSend")(_)
}
}
running this on Jenkins gives me a java.lang.IllegalStateException: There is no pipeline variable mock for [office365ConnectorSend].
, what am I doing wrong in this approach?
Aucun commentaire:
Enregistrer un commentaire