Q: WithPlugin annotation to override existing installed plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Q: WithPlugin annotation to override existing installed plugin

Victor Martinez
Hi there,

I'd like to reinstall an old version of a particular plugin in my current Unit Tests, then I can test the behaviour of my plugin with different versions of some dependent plugins.

If I didn't explain myself correctly, this is how far I went:

pom.xml

...
<dependency>
  <groupId>org.jenkins-ci.plugins</groupId>
  <artifactId>groovy</artifactId>
  <version>2.0</version>
  <scope>test</scope>
</dependency>
...

Unit Test:


// this is just using the WithPlugin annotation based on the groovy version 1.30
@WithPlugin
("groovy.hpi")
@Test public void testJobWithSystemGroovy1() throws Exception {
   
FreeStyleProject project = j.createFreeStyleProject("SystemWithSandbox");
    project.getBuildersList().add(new hudson.plugins.groovy.SystemGroovy(new StringScriptSource("println 'hi'"),null,null));
    assertTrue(checker.executeCheck(project));
}

// This is just using the pom dependencies: groovy plugin version 2.0
@Test public void testJobWithSystemGroovy2() throws Exception {
   
FreeStyleProject project = j.createFreeStyleProject("SystemWithSandbox");
    project.getBuildersList().add(new hudson.plugins.groovy.SystemGroovy(new StringScriptSource("println 'hi'"),null,null));
    assertTrue(checker.executeCheck(project));
}



Then the executeCheck method 

public boolean executeCheck(Item item) {
   
boolean found = false;
    PluginWrapper plugin = Jenkins.getInstance().pluginManager.getPlugin("groovy");
    if (plugin==null) {
       
LOG.log(Level.FINE, "Plugin Groovy isn't installed");
    } else {
       
if (plugin.getVersionNumber().isNewerThan(new hudson.util.VersionNumber("1.30"))) {
         
....
}



Unfortunately, WithPlugin doesn't work as I expect since the JenkinsRule takes the pom dependency rather than reinstalling the local one which it's stored under: ./src/test/resources/plugins/groovy.hpi

Any ideas how I can have the same plugin but in different versions while running the Unit Tests with the TestHarness framework?

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1e4a7d00-e82a-488e-a980-d9d1c1ba5d2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Q: WithPlugin annotation to override existing installed plugin

Jesse Glick-4
On Mon, Aug 7, 2017 at 7:50 AM, Victor Martinez
<[hidden email]> wrote:
> Any ideas how I can have the same plugin but in different versions while
> running the Unit Tests with the TestHarness framework?

Not supported I think. Why do you care to test against older versions
of another plugin, anyway? If there is some bug in your plugin only
triggered by some condition present in an obsolete version of another
plugin, best to create a test fixture that also triggers the same
condition.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0T6JSTN55q2_Licf7PHuXhsBJRBXGdZGzGZ-fXzjqB_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Q: WithPlugin annotation to override existing installed plugin

Victor Martinez
I'm linting Jenkins jobs and how some plugins are configured.

For instance:
- groovy plugin version 2.0 uses the script security plugin. While version 1.X no. I'd like to run one test case per version to detect whether they are configured as I expect.
- git plugin version +2.4.1 allows git reference cache repos, so I'd like to test also different versions.


At the moment I need to test it manually with the hpi:run

Does the ATH allow this use case?

Cheers

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2994b9d0-70d4-4a53-bb11-56eb45434d48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Q: WithPlugin annotation to override existing installed plugin

Jesse Glick-4
On Mon, Aug 7, 2017 at 12:24 PM, Victor Martinez
<[hidden email]> wrote:
> - groovy plugin version 2.0 uses the script security plugin. While version 1.X no. I'd like to run one test case per version to detect whether they are configured as I expect.

Just test 2.x and ignore 1.x.

> Does the ATH allow this use case?

Not really.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0zOA0UR7Uof%2BLAyHBV%2B66vdfk%3DBYaEjP6%2BJ%3Dm6T8zuAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...