Skip to content

Commit

Permalink
Added another library example with multiple params and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
macg33zr committed Aug 30, 2018
1 parent 2de86e4 commit 4b0afe2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pipelineLibrary/vars/stepWithParams.groovy
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}"
}
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)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class GlobalVariableJobTestSpec extends PipelineSpockTestBase {
assertJobStatusSuccess()

then:
testNonRegression("Parallel_Jenkinsfile_should_complete_with_success")
testNonRegression("Jenkinsfile_should_complete_with_success")
}
}
27 changes: 27 additions & 0 deletions pipelineTests/groovy/tests/library/stepWithParamsTestSpec.groovy
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")

}
}

0 comments on commit 4b0afe2

Please sign in to comment.