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

Invalid sample of setting up custom script roots locations in README.md #80

Closed
angry-cellophane opened this issue Nov 28, 2017 · 2 comments

Comments

@angry-cellophane
Copy link
Contributor

angry-cellophane commented Nov 28, 2017

https://github.com/angry-cellophane/JenkinsPipelineUnit#configuration
Overriding these default values is easy:

class TestExampleJob extends BasePipelineTest {

    @Override
    @Before
    void setUp() throws Exception {
        helper.baseScriptRoot = 'jenkinsJobs'
        helper.roots += 'src/main/groovy'
        helper.extension = 'pipeline'
        super.setUp()
    }   
}

if I use this code snippet to customize my pipeline test I have an exception that my file is not found.
I use a typical maven project structure

└── src
    ├── main
    │   └── groovy
    │      
    └── test
        ├── groovy
        └── resources

This happens because helper's properties are overridden by BasePipelineTest's properties.
https://github.com/angry-cellophane/JenkinsPipelineUnit/blob/master/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy

    void setUp() throws Exception {
        helper.with {
            it.scriptRoots = this.scriptRoots
            it.scriptExtension = this.scriptExtension
            it.baseClassloader = this.baseClassLoader
            it.imports += this.imports
            it.baseScriptRoot = this.baseScriptRoot
            return it
        }.init()
        //...
   }

If I use BasePipelineTest's properties the test works fine

class TestExampleJob extends BasePipelineTest {

    @Override
    @Before
    void setUp() throws Exception {
        baseScriptRoot = 'jenkinsJobs'
        roots += 'src/main/groovy'
        extension = 'pipeline'
        super.setUp()
    }   
}
@oliverlockwood
Copy link

I agree with @angry-cellophane's assessment here. Additionally, the roots and extension fields are actually named scriptRoots and scriptExtension.

There's a number of ways to fix this:

  1. change the documentation to reflect the current way this works (i.e. setting BasePipelineTest's properties, as @angry-cellophane points out
  2. change the behaviour - e.g. have the properties in BasePipelineTest as unmodifiable default values; apply these to the helper in the BasePipelineTest() constructor, so that people can override in their setUp() implementation.

Perhaps if one of the maintainers of this project could comment with their thoughts, then either @angry-cellophane or I could contribute a fix?

(FYI @georgelee1 as we were talking about this yesterday.)

@stchar
Copy link
Contributor

stchar commented Mar 15, 2019

Updated doc.

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

3 participants