forked from biouno/uno-choice-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-28764] Write tests and fix possible bug before shipping code
- Loading branch information
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/java/org/biouno/unochoice/issue28764/TestIssue28764.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.biouno.unochoice.issue28764; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.biouno.unochoice.model.ScriptlerScript; | ||
import org.biouno.unochoice.model.ScriptlerScriptParameter; | ||
import org.biouno.unochoice.util.Utils; | ||
import org.jenkinsci.plugins.scriptler.config.Parameter; | ||
import org.jenkinsci.plugins.scriptler.config.Script; | ||
import org.jenkinsci.plugins.scriptler.util.ScriptHelper; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({ ScriptHelper.class, Utils.class }) | ||
public class TestIssue28764 { | ||
|
||
private List<ScriptlerScriptParameter> params = null; | ||
|
||
private Script script = null; | ||
|
||
private ScriptlerScript scriptlerScript = null; | ||
|
||
private Map<String, String> myEnv = null; | ||
|
||
@Before | ||
public void setUp() { | ||
params = new ArrayList<ScriptlerScriptParameter>(); | ||
|
||
script = new Script("id", "name", "comment", true, "originCatalog", | ||
"originScript", "originDate", true, | ||
(Parameter[]) params.toArray(new Parameter[0]), false); | ||
script.setScript("if(binding.variables.get('flag') == null) {return [1, 2, 3]} else {return [1000, 100, 1]}"); | ||
|
||
myEnv = new HashMap<String, String>(); | ||
myEnv.put("flag", "myflag"); | ||
|
||
scriptlerScript = new ScriptlerScript("id", params); | ||
|
||
// Mock | ||
PowerMockito.mockStatic(Utils.class); | ||
PowerMockito.when(Utils.getSystemEnv()).thenReturn(this.myEnv); | ||
|
||
PowerMockito.mockStatic(ScriptHelper.class); | ||
PowerMockito.when( | ||
ScriptHelper.getScript(Mockito.anyString(), | ||
Mockito.anyBoolean())).thenReturn(this.script); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void testEnvVarsExpanding() { | ||
List<Integer> returnValue = (List<Integer>) scriptlerScript.eval(); | ||
assertEquals(Arrays.asList(new Integer[] { 1000, 100, 1 }), returnValue); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/test/java/org/biouno/unochoice/issue28764/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Tests for JENKINS-28764: Environment variables are not expanded and thus cannot be used as parameter values to | ||
* Scriptler scripts | ||
*/ | ||
package org.biouno.unochoice.issue28764; |
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows for the usage of environment variables in the Scriptler script, but it does not fix the expansion of environment variables which are placed in a Scriptler script parameter. Can this be fixed?
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @wykapedia
Sure, can you file an issue in issues.jenkins-ci.org, with component=active-choices-plugin, please?
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried creating an account but it says I am a spambot. Can you create the issue or instruct me on how to get an account?
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't followed exactly what's going on in the jenkins mailing list, but I saw heaps of messages about account creation. Looks like the infra guys are having some problems there.
https://issues.jenkins-ci.org/browse/JENKINS-32680
Created JENKINS-32680. I organise my work when I start a development cycle using JIRA for Jenkins plug-ins. But you can comment here if you have problems logging in to Jenkins JIRA. The only problem is that I don't get e-mails from GitHub when there are changes here (though normally I check my GitHub notifications via github.com)
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating the issue. Specifically, if I try to use a global environment variable or global password in a Scriptler parameter, it does not get expanded.
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had the same issue creating an account in the jenkins jira. For what its worth this is the work around I've been using in my own groovy scripts:
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for showing us your work around @kak-bo-che
We fixed an issue with the jenkinsProject global property, and it was fixed based on the work around of another user in Groovy. So it may definitely help when we try to tackle this problem in the next release.
Stay tuned, but feel free to bump the thread here, on Jenkins JIRA, or in our mailing list if we take too long to make progress.
All the best,
Bruno
2ee4d34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kak-bo-che Your work around was the only one, which worked for me to get environment variables.
Still less hacky approach would be nice, but none of any examples worked.