jenkinsci / JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
MIT License
1.53k stars 388 forks source link

Add override to `helper.addShMock` to accept a regexp as first argument #536

Closed lemeurherve closed 2 years ago

lemeurherve commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.350 OS: Linux - 5.4.0-1078-azure --- ace-editor:1.1 analysis-model-api:10.10.1 ansicolor:1.0.1 antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 authentication-tokens:1.4 aws-credentials:191.vcb_f183ce58b_9 aws-java-sdk-ec2:1.12.215-339.vdc07efc5320c aws-java-sdk-minimal:1.12.215-339.vdc07efc5320c azure-container-agents:241.va_780fa_dc374a_ azure-credentials:216.ve0b_4a_485ffc2 azure-sdk:106.v552de1e64d56 azure-vm-agents:816.v27bbb474b2b2 basic-branch-build-strategies:1.3.2 blueocean:1.25.5 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.25.5 blueocean-commons:1.25.5 blueocean-config:1.25.5 blueocean-core-js:1.25.5 blueocean-dashboard:1.25.5 blueocean-display-url:2.4.1 blueocean-events:1.25.5 blueocean-git-pipeline:1.25.5 blueocean-github-pipeline:1.25.5 blueocean-i18n:1.25.5 blueocean-jira:1.25.5 blueocean-jwt:1.25.5 blueocean-personalization:1.25.5 blueocean-pipeline-api-impl:1.25.5 blueocean-pipeline-editor:1.25.5 blueocean-pipeline-scm-api:1.25.5 blueocean-rest:1.25.5 blueocean-rest-impl:1.25.5 blueocean-web:1.25.5 bootstrap5-api:5.1.3-7 bouncycastle-api:2.26 branch-api:2.1046.v0ca_37783ecc5 build-name-setter:2.2.0 caffeine-api:2.9.3-65.v6a_47d0f4d1fe checks-api:1.7.4 cloud-stats:0.27 cloudbees-bitbucket-branch-source:773.v4b_9b_005b_562b_ cloudbees-folder:6.729.v2b_9d1a_74d673 cloudbees-jenkins-advisor:3.3.2 cobertura:1.17 code-coverage-api:2.0.4 command-launcher:84.v4a_97f2027398 config-file-provider:3.10.0 configuration-as-code:1429.v09b_044a_c93de copyartifact:1.46.4 credentials:1129.vef26f5df883c credentials-binding:523.vd859a_4b_122e6 dark-theme:185.v276b_5a_8966a_e data-tables-api:1.11.4-4 datadog:4.0.0 design-library:91.v257f311ea_1dc display-url-api:2.3.6 docker-commons:1.19 durable-task:496.va67c6f9eefa7 ec2:1.68 echarts-api:5.3.2-2 embeddable-build-status:2.0.3 extended-read-permission:3.2 favorite:2.4.1 font-awesome-api:6.1.1-1 forensics-api:1.13.0 git:4.11.3 git-client:3.11.0 git-forensics:1.8.0 git-server:1.11 github:1.34.3 github-api:1.303-400.v35c2d8258028 github-autostatus:3.6.2 github-branch-source:1637.vd833b_7ca_7654 github-checks:1.0.18 github-label-filter:1.0.0 groovy:2.4 handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 htmlpublisher:1.30 inline-pipeline:1.0.1 jackson2-api:2.13.3-285.vc03c0256d517 jacoco:3.3.2 javadoc:217.v905b_86277a_2a_ javax-activation-api:1.2.0-3 javax-mail-api:1.6.2-6 jaxb:2.3.6-1 jdk-tool:1.0 jenkins-design-language:1.25.5 jira:3.7.1 jjwt-api:0.11.5-77.v646c772fddb_0 jnr-posix-api:3.1.7-3 job-dsl:1.79 jquery3-api:3.6.0-4 jsch:0.1.55.2 junit:1119.va_a_5e9068da_d7 kubernetes:3600.v144b_cd192ca_a_ kubernetes-client-api:5.12.2-193.v26a_6078f65a_9 kubernetes-credentials:0.9.0 kubernetes-credentials-provider:0.20 ldap:2.10 lockable-resources:2.15 mailer:414.vcc4c33714601 matrix-auth:3.1.2 matrix-project:771.v574584b_39e60 metrics:4.1.6.2 momentjs:1.1.1 node-iterator-api:1.5.1 okhttp-api:4.9.3-105.vb96869f8ac3a pipeline-build-step:2.18 pipeline-github:2.8-138.d766e30bb08b pipeline-graph-analysis:195.v5812d95a_a_2f9 pipeline-groovy-lib:591.v3a_7f422b_d058 pipeline-input-step:448.v37cea_9a_10a_70 pipeline-milestone-step:101.vd572fef9d926 pipeline-model-api:2.2086.v12b_420f036e5 pipeline-model-definition:2.2086.v12b_420f036e5 pipeline-model-extensions:2.2086.v12b_420f036e5 pipeline-rest-api:2.24 pipeline-stage-step:293.v200037eefcd5 pipeline-stage-tags-metadata:2.2086.v12b_420f036e5 pipeline-stage-view:2.24 pipeline-utility-steps:2.12.2 plain-credentials:1.8 plugin-util-api:2.17.0 popper2-api:2.11.5-2 prism-api:1.28.0-2 prometheus:2.0.11 pubsub-light:1.16 scm-api:608.vfa_f971c5a_a_e9 scm-filter-branch-pr:0.5.1 script-security:1175.v4b_d517d6db_f0 snakeyaml-api:1.30.1 sse-gateway:1.25 ssh-agent:295.v9ca_a_1c7cc3a_a_ ssh-credentials:277.v95c2fec1c047 sshd:3.237.v883d165a_c1d3 structs:318.va_f3ccb_729b_71 support-core:1174.vc46f6b_04d894 theme-manager:1.4 timestamper:1.17 token-macro:293.v283932a_0a_b_49 toolenv:1.2 trilead-api:1.57.v6e90e07157e1 variant:1.4 warnings-ng:9.12.0 windows-azure-storage:378.vb2cb9797e1e5 workflow-aggregator:581.v0c46fa_697ffd workflow-api:1164.v760c223ddb_32 workflow-basic-steps:948.v2c72a_091b_b_68 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:625.vd896b_f445a_f8 workflow-support:820.vd1a_6cc65ef33 ```

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

Controller on Linux, agents on Linux or Windows

(It's for the pipeline library we're using on Jenkins Infrastructure, more specifically on infra.ci.jenkins.io)

Reproduction steps

  1. add helper.addShMock(~/echo\s.*/, '', 0) to a test (from the doc https://github.com/jenkinsci/JenkinsPipelineUnit#mocking-shell-steps)
  2. run the test

Expected Results

No error

Actual Results

[ERROR] myTest.setUp:43 » MissingMethod No signature of method: com.lesfurets.jenkins.unit.PipelineTestHelper.addShMock() is applicable for argument types: (java.util.regex.Pattern, String, Integer) values: [echo\s.*, , 0] Possible solutions: addShMock(java.lang.String, java.lang.String, int), addShMock(java.lang.String, groovy.lang.Closure), addBatMock(java.lang.String, java.lang.String, int), addBatMock(java.lang.String, groovy.lang.Closure)

Anything else?

Looking at the last v1.14 released code, there is only a string type signature method: https://github.com/jenkinsci/JenkinsPipelineUnit/blob/v1.14/src/main/groovy/com/lesfurets/jenkins/unit/PipelineTestHelper.groovy#L690

But looking at the primary branch we can see passing something else than a string is allowed: https://github.com/jenkinsci/JenkinsPipelineUnit/blob/master/src/main/groovy/com/lesfurets/jenkins/unit/PipelineTestHelper.groovy#L773

Could it be possible to release a new version?

nre-ableton commented 2 years ago

@lemeurherve Sorry, for the delay, I haven't had time to work on this project recently, but my team now has a hack sprint so I'll be examining this issue soon.

nre-ableton commented 2 years ago

Should be fixed by https://github.com/jenkinsci/JenkinsPipelineUnit/pull/541.