Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock object creation? #589

Open
Warchant opened this issue Feb 24, 2023 · 0 comments
Open

How to mock object creation? #589

Warchant opened this issue Feb 24, 2023 · 0 comments

Comments

@Warchant
Copy link

Warchant commented Feb 24, 2023

Describe your use-case which is not covered by existing documentation.

Documentation lacks an example which shows how to mock object creation in the pipeline.

Specifically, my jenkins controller has this plugin installed: https://plugins.jenkins.io/influxdb/
And in my shared library I have a file:
/vars/dashboard.groovy with a function that is similar to this: https://github.com/jenkinsci/influxdb-plugin#via-jenkins-pipeline

def influxDb(Map args) {
    lock(targetName) {
        // Copy from: https://github.com/jenkinsci/influxdb-plugin#via-jenkins-pipeline
        def influxdb = Jenkins.instance.getDescriptorByType(jenkinsci.plugins.influxdb.InfluxDbStep.DescriptorImpl)
        def targests = influxdb.getTargets()
        influxdb.removeTarget(targetName)
        def target = new jenkinsci.plugins.influxdb.models.Target()
        target.description = targetName
        target.url = args.dashboard.influx_server_url

See this line: def target = new jenkinsci.plugins.influxdb.models.Target().

Because local gradle project does not define any dependency on this influxdb-plugin, this class is undefined. When I attempt to load my shared library, I get an error

file:/C:/W/jenkins_shared_library/test/resources/ReportTest_WhenUnstable.Jenkinsfile: 1: Error on loading library LuCI@master : startup failed:
C:\W\jenkins_shared_library\vars\dashboard.groovy: 101: unable to resolve class jenkinsci.plugins.influxdb.models.Target
 @ line 101, column 22.
           def target = new jenkinsci.plugins.influxdb.models.Target()

I'd like to instantiate a mock here.

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant