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

JenkinsPipelineUnit - unable to mock getId() called within script block #560

Open
jordarlu opened this issue Oct 26, 2022 · 0 comments
Open

Comments

@jordarlu
Copy link

jordarlu commented Oct 26, 2022

Jenkins and plugins versions report

Environment
Jenkins: 2.332.3
OS: Linux - 4.14.294-220.533.amzn2.x86_64
---
ace-editor:1.1
adoptopenjdk:1.4
ansicolor:1.0.2
ant:475.vf34069fef73c
antisamy-markup-formatter:2.7
apache-httpcomponents-client-4-api:4.5.13-138.v4e7d9a_7b_a_e61
audit-trail:3.10
authentication-tokens:1.4
aws-credentials:191.vcb_f183ce58b_9
aws-java-sdk:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-cloudformation:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-codebuild:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-ec2:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-ecr:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-ecs:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-efs:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-elasticbeanstalk:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-iam:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-logs:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-minimal:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-sns:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-sqs:1.12.287-357.vf82d85a_6eefd
aws-java-sdk-ssm:1.12.287-357.vf82d85a_6eefd
aws-secrets-manager-credentials-provider:1.2.0
blueocean:1.25.6
blueocean-autofavorite:1.2.5
blueocean-bitbucket-pipeline:1.25.7
blueocean-commons:1.25.7
blueocean-config:1.25.7
blueocean-core-js:1.25.7
blueocean-dashboard:1.25.7
blueocean-display-url:2.4.1
blueocean-events:1.25.7
blueocean-git-pipeline:1.25.7
blueocean-github-pipeline:1.25.7
blueocean-i18n:1.25.7
blueocean-jwt:1.25.7
blueocean-personalization:1.25.7
blueocean-pipeline-api-impl:1.25.7
blueocean-pipeline-editor:1.25.7
blueocean-pipeline-scm-api:1.25.7
blueocean-rest:1.25.7
blueocean-rest-impl:1.25.7
blueocean-web:1.25.7
bootstrap4-api:4.6.0-5
bootstrap5-api:5.2.0-1
bouncycastle-api:2.26
branch-api:2.1046.v0ca_37783ecc5
build-timeout:1.21
build-timestamp:1.0.3
build-with-parameters:1.6
caffeine-api:2.9.3-65.v6a_47d0f4d1fe
checks-api:1.7.5
cloudbees-bitbucket-branch-source:784.v7fcdc7c670f6
cloudbees-folder:6.740.ve4f4ffa_dea_54
command-launcher:84.v4a_97f2027398
config-file-provider:3.10.0
configuration-as-code:1512.vb_79d418d5fc8
copyartifact:1.47
credentials:1087.1089.v2f1b_9a_b_040e4
credentials-binding:523.vd859a_4b_122e6
description-setter:1.10
disable-github-multibranch-status:1.2
display-url-api:2.3.6
docker-commons:1.21
docker-custom-build-environment:1.7.3
docker-workflow:1.28
durable-task:500.v8927d9fd99d8
ec2:2.0.1
echarts-api:5.3.3-1
email-ext:2.89
environment-script:1.2.6
extensible-choice-parameter:1.8.0
external-monitor-job:192.ve979ca_8b_3ccd
favorite:2.4.1
font-awesome-api:6.1.2-1
generic-webhook-trigger:1.84
ghprb:1.42.2
git:4.11.5
git-client:3.11.2
git-parameter:0.9.17
git-server:1.11
github:1.34.3.1
github-api:1.303-400.v35c2d8258028
github-branch-source:1637.vd833b_7ca_7654
gradle:1.39.4
greenballs:1.15.1
handlebars:3.0.8
handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953
hidden-parameter:0.0.5
htmlpublisher:1.30
ivy:2.2
jackson2-api:2.13.3-285.vc03c0256d517
javadoc:226.v71211feb_e7e9
javax-activation-api:1.2.0-3
javax-mail-api:1.6.2-6
jaxb:2.3.6-1
jdk-tool:55.v1b_32b_6ca_f9ca
jenkins-design-language:1.25.7
jjwt-api:0.11.5-77.v646c772fddb_0
job-dsl:1.81
job-import-plugin:3.5
job-restrictions:0.8
jobConfigHistory:1139.v888b_656ca_f6d
jquery:1.12.4-1
jquery3-api:3.6.0-4
jsch:0.1.55.61.va_e9ee26616e7
junit:1119.va_a_5e9068da_d7
ldap:2.10
lockable-resources:2.16
login-theme:1.1
mailer:414.vcc4c33714601
managed-scripts:1.5.4
matrix-auth:3.1.5
matrix-project:772.v494f19991984
maven-plugin:3.19
mina-sshd-api-common:2.8.0-18.vd98674ecd652
mina-sshd-api-core:2.8.0-18.vd98674ecd652
momentjs:1.1.1
node-iterator-api:1.5.1
nodelabelparameter:1.11.0
nvm-wrapper:0.1.7
oic-auth:1.8
okhttp-api:4.9.3-108.v0feda04578cf
openJDK-native-plugin:1.5
ownership:0.13.0
pam-auth:1.10
parameterized-scheduler:1.0
pipeline-aws:1.43
pipeline-build-step:2.18
pipeline-github-lib:38.v445716ea_edda_
pipeline-graph-analysis:195.v5812d95a_a_2f9
pipeline-groovy-lib:612.v84da_9c54906d
pipeline-input-step:449.v77f0e8b_845c4
pipeline-milestone-step:101.vd572fef9d926
pipeline-model-api:2.2097.v33db_b_de764b_e
pipeline-model-definition:2.2064.v5eef7d0982b_e
pipeline-model-extensions:2.2097.v33db_b_de764b_e
pipeline-rest-api:2.24
pipeline-stage-step:293.v200037eefcd5
pipeline-stage-tags-metadata:2.2097.v33db_b_de764b_e
pipeline-stage-view:2.24
pipeline-utility-steps:2.13.0
plain-credentials:139.ved2b_9cf7587b
plugin-util-api:2.17.0
popper-api:1.16.1-3
popper2-api:2.11.6-1
postbuild-task:1.9
postbuildscript:3.1.0-375.v3db_cd92485e1
powershell:1.7
preSCMbuildstep:0.3
project-description-setter:1.2
pubsub-light:1.16
python:1.3
readonly-parameters:1.0.0
rebuild:1.34
resource-disposer:0.19
role-strategy:561.v9846c7351a_41
s3:0.12.2
saml:2.298.vc7a_2b_3958628
scm-api:621.vda_a_b_055e58f7
script-security:1175.v4b_d517d6db_f0
simple-theme-plugin:103.va_161d09c38c7
snakeyaml-api:1.30.2-76.vc104f7ce9870
sse-gateway:1.25
ssh-credentials:277.280.v1e86b_7d0056b_
ssh-slaves:1.821.vd834f8a_c390e
sshd:3.242.va_db_9da_b_26a_c3
strict-crumb-issuer:2.1.0
structs:324.va_f5d6774f3a_d
throttle-concurrents:2.8
timestamper:1.18
token-macro:308.v4f2b_ed62b_b_16
trilead-api:1.67.vc3938a_35172f
uno-choice:2.6.2
validating-string-parameter:2.8
variant:59.vf075fe829ccb
windows-slaves:1.8.1
workflow-aggregator:590.v6a_d052e5a_a_b_5
workflow-api:1164.v760c223ddb_32
workflow-basic-steps:941.vdfe1b_a_132c64
workflow-cps:2725.v7b_c717eb_12ce
workflow-cps-global-lib:588.v576c103a_ff86
workflow-durable-task-step:1144.vd77b_57189936
workflow-job:1186.v8def1a_5f3944
workflow-multibranch:716.vc692a_e52371b_
workflow-scm-step:400.v6b_89a_1317c9a_
workflow-step-api:639.v6eca_cd8c04a_a_
workflow-support:820.vd1a_6cc65ef33
ws-cleanup:0.42

What Operating System are you using (both controller, and any agents involved in the problem)?

I am running the unit test using JenkinsPipelineUnit framwork and test at my local Macbook

Reproduction steps

I try to come out a groovy test for a .jenkinsfile with using the JenkinsPipelineUnit framwork and test at my local Macbook.

In one of the .jenkinsfile which it has the following structure:
https://github.com/opensearch-project/opensearch-build/blob/main/jenkins/opensearch-dashboards/distribution-build.jenkinsfile#L159-L186
The getId() at L#176 is always caught error as " No signature of method: java.util.LinkedHashMap.getId() is applicable for argument types: () values: []
Possible solutions: get(java.lang.Object), get(java.lang.Object), get(java.lang.Object), getAt(java.lang.Object), getAt(java.lang.String), get(java.lang.Object, java.lang.Object)"

I have tried the following but still no luck

binding.setVariable('getId', '123456')
helper.registerAllowedMethod('getId', [], {})

could it be some issues mocking a function/method inside the script block?
If there is any workaround for the cases like this?

thanks,

Expected Results

Expecting to be able to Mock getId() or Mock the entire library (L#174 buildInfoYaml() in this case), so, I can unit test just the .jenkinsfile alone.
The getId() is in Class Run as at here https://javadoc.jenkins-ci.org/hudson/model/Run.html

Actual Results

Task :test FAILED

TestOpenSearchDashboardsDistributionBuild > testDistributionBuild_Pipeline FAILED
java.lang.RuntimeException: integ-test - No signature of method: java.util.LinkedHashMap.getId() is applicable for argument types: () values: []
Possible solutions: get(java.lang.Object), get(java.lang.Object), get(java.lang.Object), getAt(java.lang.Object), getAt(java.lang.String), get(java.lang.Object, java.lang.Object),bwc-test - No signature of method: java.util.LinkedHashMap.getId() is applicable for argument types: () values: []
Possible solutions: get(java.lang.Object), get(java.lang.Object), get(java.lang.Object), getAt(java.lang.Object), getAt(java.lang.String), get(java.lang.Object, java.lang.Object)

Anything else?

No response

@jordarlu jordarlu changed the title JenkinsPipelineUnit - unable to mock getId() called within parrallel JenkinsPipelineUnit - unable to mock getId() called within script block Oct 26, 2022
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