ExpediaGroup / jenkins-spock

Unit-test Jenkins pipeline code with Spock
https://javadoc.io/doc/com.homeaway.devtools.jenkins/jenkins-spock
Apache License 2.0
186 stars 73 forks source link

Unable to mock 'bat' step if 'label' contains Unicode character #130

Open mdealer opened 1 year ago

mdealer commented 1 year ago

Expected Behavior

Proper Unicode handling and mock of the step.

Actual Behavior

It does not mock the step.

Steps to Reproduce

  1. Create a Jenkins Shared Groovy Library
  2. Implement some function to be called later that contains a 'bat' step with a 'label' that contains a Unicode char.
  3. Add tests using jenkins-spock and mock the 'bat' step

Additional Information

The bat step in question is roughly: output = script.bat script: '@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaa@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa', returnStdout: true, encoding: 'UTF-8', label: 'Batch Script (💻myhostname)'

The setup function / test class is roughly: import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification

class createBuilderSpec extends JenkinsPipelineSpecification {
    def setup() {
        // ...
        getPipelineMock('bat')([returnStdout: true, script: 'hostname']) >> 'myhostname' // Some other step which just works fine
    getPipelineMock("bat")([script:'@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa', returnStdout:true, encoding:'UTF-8', label:'Batch Script (💻myhostname)']) >> 'someresult'
         // ...
    }
// ...

Spock does not handle the Unicode character, I can see it in the console:

10:11:07.598 [main] DEBUG com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification - TEST FIXTURE intercepted & redirected a call:
    Test         : class com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification
    Note         : pipeline step 
    Via          : createBuilder@4cb773c5.methodMissing
        (types)  : createBuilder.methodMissing
    Invocation   : createBuilder@4cb773c5.bat([[script:@echo off && aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa, returnStdout:true, encoding:UTF-8, label:Batch Script (­ƒÆ╗myhostname)]])
        (types)  : createBuilder.bat(Object[])
    Forwarded To : Mock for type 'Closure' named 'getPipelineMock("bat")'.call([script:aaa aaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa, returnStdout:true, encoding:UTF-8, label:Batch Script (­ƒÆ╗myhostname)])
        (types)  : Closure$$EnhancerByCGLIB$$923b74da.call(LinkedHashMap)

As long as the character is in there, the mock is not actually called and the 'bat' step returns null.

I'm on Windows with Java 11 64-bit and Groovy 2.4.12.

Having Unicode in Strings works fine in Jenkins.