2021-08-18 12:10:55 +02:00
|
|
|
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
|
2021-12-08 18:13:20 +02:00
|
|
|
import static org.junit.Assert.assertTrue
|
2021-08-18 12:10:55 +02:00
|
|
|
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,
|
2021-12-08 18:13:20 +02:00
|
|
|
calledWithCredentials,
|
|
|
|
calledWithFailOnError
|
2021-08-18 12:10:55 +02:00
|
|
|
|
|
|
|
helper.registerAllowedMethod(
|
|
|
|
'piperExecuteBin',
|
2021-12-08 18:13:20 +02:00
|
|
|
[Map, String, String, List, Boolean, Boolean, Boolean],
|
2021-08-18 12:10:55 +02:00
|
|
|
{
|
2021-12-08 18:13:20 +02:00
|
|
|
params, stepName, metaData, creds, failOnMissingReports, failOnMissingLinks, failOnError ->
|
2021-08-18 12:10:55 +02:00
|
|
|
calledWithParameters = params
|
|
|
|
calledWithStepName = stepName
|
|
|
|
calledWithMetadata = metaData
|
|
|
|
calledWithCredentials = creds
|
2021-12-08 18:13:20 +02:00
|
|
|
calledWithFailOnError = failOnError
|
2021-08-18 12:10:55 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-09-29 18:21:13 +02:00
|
|
|
stepRule.step.cnbBuild(
|
|
|
|
script: nullScript,
|
|
|
|
buildpacks: ['test1', 'test2'],
|
|
|
|
containerImageName: 'foo',
|
|
|
|
containerImageTag: 'bar',
|
|
|
|
containerRegistryUrl: 'test',
|
|
|
|
dockerConfigJsonCredentialsId: 'DOCKER_CREDENTIALS',
|
|
|
|
buildEnvVars: ['foo=bar', 'bar=baz']
|
|
|
|
)
|
2021-08-18 12:10:55 +02:00
|
|
|
|
2021-09-29 18:21:13 +02:00
|
|
|
assertThat(calledWithParameters.size(), is(7))
|
2021-08-18 12:10:55 +02:00
|
|
|
assertThat(calledWithParameters.script, is(nullScript))
|
2021-09-14 16:14:50 +02:00
|
|
|
assertThat(calledWithParameters.buildpacks, is(['test1', 'test2']))
|
2021-08-26 14:26:54 +02:00
|
|
|
assertThat(calledWithParameters.containerImageName, is('foo'))
|
|
|
|
assertThat(calledWithParameters.containerImageTag, is('bar'))
|
|
|
|
assertThat(calledWithParameters.containerRegistryUrl, is('test'))
|
2021-08-18 12:10:55 +02:00
|
|
|
assertThat(calledWithParameters.dockerConfigJsonCredentialsId, is('DOCKER_CREDENTIALS'))
|
2021-09-29 18:21:13 +02:00
|
|
|
assertThat(calledWithParameters.buildEnvVars, is(['foo=bar', 'bar=baz']))
|
2021-08-18 12:10:55 +02:00
|
|
|
|
|
|
|
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'])))
|
|
|
|
|
2021-12-08 18:13:20 +02:00
|
|
|
assertTrue(calledWithFailOnError)
|
|
|
|
|
2021-08-18 12:10:55 +02:00
|
|
|
}
|
|
|
|
}
|