2020-02-25 11:20:15 +02:00
|
|
|
import org.junit.Before
|
2018-07-30 09:28:24 +02:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
import util.BasePiperTest
|
2018-09-03 11:09:09 +02:00
|
|
|
import util.JenkinsCredentialsRule
|
2018-07-30 09:28:24 +02:00
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.Rules
|
2020-07-06 11:45:36 +02:00
|
|
|
import static org.junit.Assert.assertEquals
|
2020-02-25 11:20:15 +02:00
|
|
|
import static org.junit.Assert.assertTrue
|
2018-07-30 09:28:24 +02:00
|
|
|
|
|
|
|
class CloudFoundryDeployTest extends BasePiperTest {
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2020-02-25 11:20:15 +02:00
|
|
|
private JenkinsCredentialsRule credentialsRule = new JenkinsCredentialsRule(this)
|
|
|
|
|
2018-07-30 09:28:24 +02:00
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
2020-02-25 11:20:15 +02:00
|
|
|
.around(credentialsRule)
|
2019-01-22 10:34:18 +02:00
|
|
|
.around(stepRule) // needs to be activated after dockerExecuteRule, otherwise executeDocker is not mocked
|
2018-07-30 09:28:24 +02:00
|
|
|
|
2019-01-18 09:25:22 +02:00
|
|
|
@Before
|
|
|
|
void init() {
|
2020-02-25 11:20:15 +02:00
|
|
|
// removing additional credentials tests might have added; adding default credentials
|
|
|
|
credentialsRule.reset()
|
|
|
|
.withCredentials('test_cfCredentialsId', 'test_cf', '********')
|
2018-11-27 12:47:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-11-09 08:44:31 +02:00
|
|
|
void testGoStepWithMtaExtensionCredentialsFromParams() {
|
2020-08-24 18:10:45 +02:00
|
|
|
String calledStep = ''
|
|
|
|
String usedMetadataFile = ''
|
2021-01-12 10:17:34 +02:00
|
|
|
List credInfo = []
|
2020-08-24 18:10:45 +02:00
|
|
|
helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], {
|
|
|
|
Map parameters, String stepName,
|
|
|
|
String metadataFile, List credentialInfo ->
|
|
|
|
calledStep = stepName
|
|
|
|
usedMetadataFile = metadataFile
|
2021-01-12 10:17:34 +02:00
|
|
|
credInfo = credentialInfo
|
2020-08-24 18:10:45 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
stepRule.step.cloudFoundryDeploy([
|
2021-11-09 08:44:31 +02:00
|
|
|
script : nullScript,
|
|
|
|
juStabUtils : utils,
|
|
|
|
useGoStep : true,
|
2021-01-12 10:17:34 +02:00
|
|
|
mtaExtensionCredentials: [myCred: 'Mta.ExtensionCredential~Credential_Id1'],
|
2020-08-24 18:10:45 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
assertEquals('cloudFoundryDeploy', calledStep)
|
|
|
|
assertEquals('metadata/cloudFoundryDeploy.yaml', usedMetadataFile)
|
2021-01-12 10:17:34 +02:00
|
|
|
|
|
|
|
// contains assertion does not work apparently when comparing a list of lists agains an expected list.
|
|
|
|
boolean found = false
|
2021-11-09 08:44:31 +02:00
|
|
|
credInfo.each { entry ->
|
|
|
|
if (entry == [type: 'token', id: 'Mta.ExtensionCredential~Credential_Id1', env: ['MTA_EXTENSION_CREDENTIAL_CREDENTIAL_ID1'], resolveCredentialsId: false]) {
|
|
|
|
found = true
|
2021-01-12 10:17:34 +02:00
|
|
|
}
|
2021-11-09 08:44:31 +02:00
|
|
|
}
|
2021-01-12 10:17:34 +02:00
|
|
|
assertTrue(found)
|
2020-08-24 18:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-11-09 08:44:31 +02:00
|
|
|
void testGoStepWithMtaExtensionCredentialsFromConfig() {
|
2020-08-24 18:10:45 +02:00
|
|
|
String calledStep = ''
|
|
|
|
String usedMetadataFile = ''
|
2021-11-09 08:44:31 +02:00
|
|
|
List credInfo = []
|
2020-08-24 18:10:45 +02:00
|
|
|
helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], {
|
|
|
|
Map parameters, String stepName,
|
|
|
|
String metadataFile, List credentialInfo ->
|
|
|
|
calledStep = stepName
|
|
|
|
usedMetadataFile = metadataFile
|
2021-11-09 08:44:31 +02:00
|
|
|
credInfo = credentialInfo
|
2020-08-24 18:10:45 +02:00
|
|
|
})
|
|
|
|
|
2021-11-09 08:44:31 +02:00
|
|
|
nullScript.commonPipelineEnvironment.configuration = [steps:[cloudFoundryDeploy:[
|
|
|
|
mtaExtensionCredentials: [myCred: 'Mta.ExtensionCredential~Credential_Id1']
|
|
|
|
]]]
|
|
|
|
|
2020-08-24 18:10:45 +02:00
|
|
|
stepRule.step.cloudFoundryDeploy([
|
2021-11-09 08:44:31 +02:00
|
|
|
script : nullScript,
|
|
|
|
juStabUtils : utils,
|
|
|
|
useGoStep : true,
|
2020-08-24 18:10:45 +02:00
|
|
|
])
|
|
|
|
|
2021-11-09 08:44:31 +02:00
|
|
|
assertEquals('cloudFoundryDeploy', calledStep)
|
|
|
|
assertEquals('metadata/cloudFoundryDeploy.yaml', usedMetadataFile)
|
|
|
|
|
|
|
|
// contains assertion does not work apparently when comparing a list of lists agains an expected list.
|
|
|
|
boolean found = false
|
|
|
|
credInfo.each { entry ->
|
|
|
|
if (entry == [type: 'token', id: 'Mta.ExtensionCredential~Credential_Id1', env: ['MTA_EXTENSION_CREDENTIAL_CREDENTIAL_ID1'], resolveCredentialsId: false]) {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertTrue(found)
|
2020-08-24 18:10:45 +02:00
|
|
|
}
|
2018-07-30 09:28:24 +02:00
|
|
|
}
|