1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00
sap-jenkins-library/test/groovy/CnbBuildTest.groovy
Pavel Busko 01c687bbdc
Broken single containerImage argument has been removed (#3065)
* Broken single containerImage argument has been removed

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>

* revert containerRegistryUrl param name

Co-authored-by: Pavel Busko <pavel.busko@sap.com>

* mark containerImageName, containerImageTag and containerRegistryUrl as mandatory arguments

Co-authored-by: Pavel Busko <pavel.busko@sap.com>
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Benjamin Haegenlaeuer <benjamin.haegenlaeuer@sap.com>
2021-08-26 14:26:54 +02:00

64 lines
2.2 KiB
Groovy

import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsReadYamlRule
import util.JenkinsStepRule
import util.Rules
import static org.junit.Assert.assertThat
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.hasEntry
import static org.hamcrest.Matchers.allOf
public class CnbBuildTest extends BasePiperTest {
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(stepRule)
.around(readYamlRule)
@Test
void testCallGoWrapper() {
def calledWithParameters,
calledWithStepName,
calledWithMetadata,
calledWithCredentials
helper.registerAllowedMethod(
'piperExecuteBin',
[Map, String, String, List],
{
params, stepName, metaData, creds ->
calledWithParameters = params
calledWithStepName = stepName
calledWithMetadata = metaData
calledWithCredentials = creds
}
)
stepRule.step.cnbBuild(script: nullScript, containerImageName: 'foo', containerImageTag: 'bar', containerRegistryUrl: 'test', dockerConfigJsonCredentialsId: 'DOCKER_CREDENTIALS')
assertThat(calledWithParameters.size(), is(5))
assertThat(calledWithParameters.script, is(nullScript))
assertThat(calledWithParameters.containerImageName, is('foo'))
assertThat(calledWithParameters.containerImageTag, is('bar'))
assertThat(calledWithParameters.containerRegistryUrl, is('test'))
assertThat(calledWithParameters.dockerConfigJsonCredentialsId, is('DOCKER_CREDENTIALS'))
assertThat(calledWithStepName, is('cnbBuild'))
assertThat(calledWithMetadata, is('metadata/cnbBuild.yaml'))
assertThat(calledWithCredentials.size(), is(1))
assertThat(calledWithCredentials[0].size(), is(3))
assertThat(calledWithCredentials[0], allOf(hasEntry('type','file'), hasEntry('id','dockerConfigJsonCredentialsId'), hasEntry('env',['PIPER_dockerConfigJSON'])))
}
}