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