github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/isChangeInDevelopmentTest.groovy (about) 1 import org.junit.Before 2 import org.junit.Ignore 3 import org.junit.Rule 4 import org.junit.Test 5 import org.junit.rules.ExpectedException 6 import org.junit.rules.RuleChain 7 import org.yaml.snakeyaml.parser.ParserException 8 9 import hudson.AbortException 10 import util.BasePiperTest 11 import util.JenkinsDockerExecuteRule 12 import util.JenkinsLoggingRule 13 import util.JenkinsReadYamlRule 14 import util.JenkinsShellCallRule 15 import util.JenkinsStepRule 16 import util.JenkinsWriteFileRule 17 import util.Rules 18 19 import static org.hamcrest.Matchers.* 20 import static org.junit.Assert.assertThat 21 import static org.hamcrest.Matchers.hasEntry 22 23 public class isChangeInDevelopmentTest extends BasePiperTest { 24 25 private JenkinsStepRule stepRule = new JenkinsStepRule(this) 26 private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this) 27 28 @Rule 29 public RuleChain ruleChain = Rules 30 .getCommonRules(this) 31 .around(stepRule) 32 .around(readYamlRule) 33 34 @Test 35 void testCallGoWrapper() { 36 37 def calledWithParameters, 38 calledWithStepName, 39 calledWithMetadata 40 List calledWithCredentials 41 42 helper.registerAllowedMethod( 43 'piperExecuteBin', 44 [Map, String, String, List], 45 { 46 params, stepName, metaData, creds -> 47 calledWithParameters = params 48 calledWithStepName = stepName 49 calledWithMetadata = metaData 50 calledWithCredentials = creds 51 } 52 ) 53 54 stepRule.step.isChangeInDevelopment(script: nullScript, abc: 'CF') 55 56 assertThat(calledWithParameters.size(), is(2)) 57 assertThat(calledWithParameters.script, is(nullScript)) 58 assertThat(calledWithParameters.abc, is('CF')) 59 60 assertThat(calledWithStepName, is('isChangeInDevelopment')) 61 assertThat(calledWithMetadata, is('metadata/isChangeInDevelopment.yaml')) 62 assertThat(calledWithCredentials[0].size(), is(3)) 63 assertThat(calledWithCredentials[0], allOf(hasEntry('type','usernamePassword'), hasEntry('id','credentialsId'), hasEntry('env',['PIPER_username', 'PIPER_password']))) 64 } 65 }