-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added another library example with multiple params and unit test
- Loading branch information
Showing
5 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Example of a library step with parameters | ||
* | ||
* In the job you can call it like this: | ||
* | ||
* steps { | ||
* stepWithParams("param1 value", "param2 value", 12345) | ||
* } | ||
* | ||
* To mock it in a Unit test of a pipeline add code like this: | ||
* | ||
* helper.registerAllowedMethod('stepWithParams', [String.class, String.class, Integer.class], null) | ||
* | ||
*/ | ||
|
||
def call(String param1, String param2, Integer param3) { | ||
|
||
echo "param1 = ${param1}" | ||
echo "param2 = ${param2}" | ||
echo "param3 = ${param3}" | ||
} |
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
pipelineTests/groovy/tests/callstacks/stepWithParamsTestSpec_should_echo_values.txt
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,4 @@ | ||
stepWithParams.call(param1 value, param2 value, 12345) | ||
stepWithParams.echo(param1 = param1 value) | ||
stepWithParams.echo(param2 = param2 value) | ||
stepWithParams.echo(param3 = 12345) |
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
27 changes: 27 additions & 0 deletions
27
pipelineTests/groovy/tests/library/stepWithParamsTestSpec.groovy
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,27 @@ | ||
package tests.library | ||
|
||
import testSupport.PipelineSpockTestBase | ||
|
||
class stepWithParamsTestSpec extends PipelineSpockTestBase { | ||
|
||
def "stepWithParams should echo param values"() { | ||
|
||
given: | ||
def param1 = 'param1 value' | ||
def param2 = 'param2 value' | ||
def param3 = 12345 | ||
|
||
|
||
when: | ||
def script = loadScript('pipelineLibrary/vars/stepWithParams.groovy') | ||
script.call(param1, param2, param3) | ||
|
||
then: | ||
printCallStack() | ||
assertJobStatusSuccess() | ||
|
||
then: | ||
testNonRegression("should_echo_values") | ||
|
||
} | ||
} |