2019-01-18 09:25:22 +02:00
import com.sap.piper.JenkinsUtils
2020-01-22 11:50:26 +02:00
import org.junit.After
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.ExpectedException
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.JenkinsDockerExecuteRule
2020-02-25 11:20:15 +02:00
import util.JenkinsEnvironmentRule
2019-09-24 08:49:25 +02:00
import util.JenkinsFileExistsRule
2018-07-30 09:28:24 +02:00
import util.JenkinsLoggingRule
2019-01-30 11:07:00 +02:00
import util.JenkinsReadFileRule
2020-02-25 11:20:15 +02:00
import util.JenkinsReadYamlRule
2018-07-30 09:28:24 +02:00
import util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.JenkinsWriteFileRule
import util.Rules
2020-02-25 11:20:15 +02:00
import static org . hamcrest . Matchers . allOf
import static org . hamcrest . Matchers . containsString
import static org . hamcrest . Matchers . equalTo
import static org . hamcrest . Matchers . hasEntry
2018-08-29 10:01:16 +02:00
import static org . hamcrest . Matchers . hasItem
2019-01-18 09:25:22 +02:00
import static org . hamcrest . Matchers . is
2018-11-27 12:47:44 +02:00
import static org . hamcrest . Matchers . not
2020-02-25 11:20:15 +02:00
import static org . hamcrest . Matchers . stringContainsInOrder
import static org . junit . Assert . assertNotNull
import static org . junit . Assert . assertThat
import static org . junit . Assert . assertTrue
2018-07-30 09:28:24 +02:00
class CloudFoundryDeployTest extends BasePiperTest {
2019-01-30 11:07:00 +02:00
private File tmpDir = File . createTempDir ( )
2018-07-30 09:28:24 +02:00
private ExpectedException thrown = ExpectedException . none ( )
2019-01-22 10:22:15 +02:00
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule ( this )
2019-01-22 10:19:28 +02:00
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule ( this )
2019-01-22 10:29:15 +02:00
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule ( this )
2019-01-30 11:07:00 +02:00
private JenkinsReadFileRule readFileRule = new JenkinsReadFileRule ( this , tmpDir . getAbsolutePath ( ) )
2019-01-22 10:34:18 +02:00
private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule ( this )
2019-01-22 10:25:42 +02:00
private JenkinsStepRule stepRule = new JenkinsStepRule ( this )
2019-01-22 10:27:45 +02:00
private JenkinsEnvironmentRule environmentRule = new JenkinsEnvironmentRule ( this )
2019-01-22 10:27:01 +02:00
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule ( this )
2019-09-27 16:10:43 +02:00
private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule ( this , [ ] )
2020-02-25 11:20:15 +02:00
private JenkinsCredentialsRule credentialsRule = new JenkinsCredentialsRule ( this )
2018-07-30 09:28:24 +02:00
2019-01-18 09:25:22 +02:00
private writeInfluxMap = [ : ]
class JenkinsUtilsMock extends JenkinsUtils {
def isJobStartedByUser ( ) {
return true
}
}
2018-07-30 09:28:24 +02:00
@Rule
public RuleChain rules = Rules
. getCommonRules ( this )
2019-01-22 10:27:01 +02:00
. around ( readYamlRule )
2018-07-30 09:28:24 +02:00
. around ( thrown )
2019-01-22 10:22:15 +02:00
. around ( loggingRule )
2019-01-22 10:19:28 +02:00
. around ( shellRule )
2019-01-22 10:29:15 +02:00
. around ( writeFileRule )
2019-01-30 11:07:00 +02:00
. around ( readFileRule )
2019-09-24 08:49:25 +02:00
. around ( fileExistsRule )
2019-01-22 10:34:18 +02:00
. around ( dockerExecuteRule )
2019-01-22 10:27:45 +02:00
. around ( environmentRule )
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' , '********' )
UUID . metaClass . static . randomUUID = { - > 1 }
helper . registerAllowedMethod ( 'influxWriteData' , [ Map . class ] , { m - >
2019-01-18 09:25:22 +02:00
writeInfluxMap = m
} )
}
2020-01-22 11:50:26 +02:00
@After
void tearDown ( ) {
UUID . metaClass = null
}
2018-07-30 09:28:24 +02:00
@Test
void testNoTool ( ) throws Exception {
nullScript . commonPipelineEnvironment . configuration = [
general: [
camSystemRole: 'testRole' ,
cfCredentialsId: 'myCreds'
] ,
stages: [
acceptance: [
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
deployUser: 'testUser' ,
]
] ,
steps: [
cloudFoundryDeploy: [ ]
]
]
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: '' ,
stageName: 'acceptance' ,
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-03-28 15:38:25 +02:00
assertThat ( loggingRule . log , containsString ( '[cloudFoundryDeploy] General parameters: deployTool=, deployType=standard, cfApiEndpoint=https://api.cf.eu10.hana.ondemand.com, cfOrg=testOrg, cfSpace=testSpace, cfCredentialsId=myCreds' ) )
2019-09-20 09:57:28 +02:00
assertThat ( loggingRule . log , containsString ( '[cloudFoundryDeploy] WARNING! Found unsupported deployTool. Skipping deployment.' ) )
2018-07-30 09:28:24 +02:00
}
@Test
void testNotAvailableTool ( ) throws Exception {
nullScript . commonPipelineEnvironment . configuration = [
general: [
cfCredentialsId: 'myCreds'
] ,
stages: [
acceptance: [
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
deployUser: 'testUser' ,
]
] ,
steps: [
cloudFoundryDeploy: [ ]
]
]
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'notAvailable' ,
stageName: 'acceptance'
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-03-28 15:38:25 +02:00
assertThat ( loggingRule . log , containsString ( '[cloudFoundryDeploy] General parameters: deployTool=notAvailable, deployType=standard, cfApiEndpoint=https://api.cf.eu10.hana.ondemand.com, cfOrg=testOrg, cfSpace=testSpace, cfCredentialsId=myCreds' ) )
2019-09-20 09:57:28 +02:00
assertThat ( loggingRule . log , containsString ( '[cloudFoundryDeploy] WARNING! Found unsupported deployTool. Skipping deployment.' ) )
2018-07-30 09:28:24 +02:00
}
2020-02-25 11:20:15 +02:00
2018-07-30 09:28:24 +02:00
@Test
void testCfNativeWithAppName ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2018-10-17 11:01:09 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-07-30 09:28:24 +02:00
}
@Test
void testCfNativeWithAppNameCustomApi ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2018-10-17 11:01:09 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'cf_native' ,
cfApiEndpoint: 'https://customApi' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://customApi -o "testOrg" -s "testSpace"' ) ) )
2018-07-30 09:28:24 +02:00
}
@Test
void testCfNativeWithAppNameCompatible ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2018-10-17 11:01:09 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'cf_native' ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
credentialsId: 'test_cfCredentialsId' ,
appName: 'testAppName' ,
manifest: 'test.yml'
]
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-07-30 09:28:24 +02:00
}
2020-02-25 11:20:15 +02:00
@Test
void testCfNativeWithDockerImage ( ) {
// adding additional credentials for Docker registry authorization
credentialsRule . withCredentials ( 'test_cfDockerCredentialsId' , 'test_cf_docker' , '********' )
readYamlRule . registerYaml ( 'test.yml' , "applications: [[name: 'manifestAppName']]" )
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployDockerImage: 'repo/image:tag' ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
credentialsId: 'test_cfCredentialsId' ,
appName: 'testAppName'
]
] )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf push testAppName --docker-image repo/image:tag' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf logout' ) ) )
}
@Test
void testCfNativeWithDockerImageAndCredentials ( ) {
// adding additional credentials for Docker registry authorization
credentialsRule . withCredentials ( 'test_cfDockerCredentialsId' , 'test_cf_docker' , '********' )
readYamlRule . registerYaml ( 'test.yml' , "applications: [[name: 'manifestAppName']]" )
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployDockerImage: 'repo/image:tag' ,
dockerCredentialsId: 'test_cfDockerCredentialsId' ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
credentialsId: 'test_cfCredentialsId' ,
appName: 'testAppName'
]
] )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( equalTo ( 'CF_DOCKER_PASSWORD' ) , equalTo ( "${'********'}" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf push testAppName --docker-image repo/image:tag --docker-username test_cf_docker' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf logout' ) ) )
}
@Test
void testCfNativeWithManifestAndDockerCredentials ( ) {
// Docker image can be done via manifest.yml; if a private Docker registry is used, --docker-username and DOCKER_PASSWORD
// must be set; this is checked by this test
// adding additional credentials for Docker registry authorization
credentialsRule . withCredentials ( 'test_cfDockerCredentialsId' , 'test_cf_docker' , '********' )
readYamlRule . registerYaml ( 'test.yml' , "applications: [[name: 'manifestAppName']]" )
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
dockerCredentialsId: 'test_cfDockerCredentialsId' ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
credentialsId: 'test_cfCredentialsId' ,
appName: 'testAppName' ,
manifest: 'manifest.yml'
]
] )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( equalTo ( 'CF_DOCKER_PASSWORD' ) , equalTo ( "${'********'}" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'manifest.yml' --docker-username test_cf_docker" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf logout' ) ) )
}
2020-04-07 09:10:38 +02:00
@Test
void testCfNativeBlueGreenWithManifestAndDockerCredentials ( ) {
// Blue Green Deploy cf cli plugin does not support --docker-username and --docker-image parameters
// docker username and docker image have to be set in the manifest file
// if a private docker repository is used the CF_DOCKER_PASSWORD env variable must be set
credentialsRule . withCredentials ( 'test_cfDockerCredentialsId' , 'test_cf_docker' , '********' )
readYamlRule . registerYaml ( 'manifest.yml' , "applications: [[name: 'manifestAppName']]" )
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
dockerCredentialsId: 'test_cfDockerCredentialsId' ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
credentialsId: 'test_cfCredentialsId' ,
appName: 'testAppName' ,
manifest: 'manifest.yml'
]
] )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( equalTo ( 'CF_DOCKER_PASSWORD' ) , equalTo ( "${'********'}" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName --delete-old-apps -f 'manifest.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf logout' ) ) )
}
2018-07-30 09:28:24 +02:00
@Test
void testCfNativeAppNameFromManifest ( ) {
2019-09-24 08:49:25 +02:00
fileExistsRule . registerExistingFile ( 'test.yml' )
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2018-10-17 11:01:09 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2018-07-30 09:28:24 +02:00
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfManifest: 'test.yml'
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-07-30 09:28:24 +02:00
}
@Test
void testCfNativeWithoutAppName ( ) {
2019-09-24 08:49:25 +02:00
fileExistsRule . registerExistingFile ( 'test.yml' )
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-10-17 11:01:09 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2018-07-30 09:28:24 +02:00
thrown . expect ( hudson . AbortException )
thrown . expectMessage ( '[cloudFoundryDeploy] ERROR: No appName available in manifest test.yml.' )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfManifest: 'test.yml'
] )
}
2018-11-07 11:39:30 +02:00
@Test
2018-11-27 12:47:44 +02:00
void testCfNativeBlueGreenDefaultDeleteOldInstance ( ) {
2018-11-07 11:39:30 +02:00
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-11-07 11:39:30 +02:00
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-11-07 11:39:30 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-11-07 11:39:30 +02:00
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
2018-11-07 11:39:30 +02:00
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-11-27 12:47:44 +02:00
}
@Test
void testCfNativeBlueGreenExplicitDeleteOldInstance ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-11-27 12:47:44 +02:00
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-11-27 12:47:44 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-11-27 12:47:44 +02:00
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
keepOldInstance: false ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
2018-11-27 12:47:44 +02:00
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'" ) ) )
2019-01-30 11:07:00 +02:00
assertThat ( shellRule . shell , not ( hasItem ( containsString ( "cf stop testAppName-old &>" ) ) ) )
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-11-27 12:47:44 +02:00
2018-11-07 11:39:30 +02:00
}
2018-11-27 12:47:44 +02:00
@Test
void testCfNativeBlueGreenKeepOldInstance ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-11-27 12:47:44 +02:00
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-11-27 12:47:44 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-11-27 12:47:44 +02:00
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
keepOldInstance: true ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
2018-11-27 12:47:44 +02:00
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName -f 'test.yml'" ) ) )
2019-01-30 11:07:00 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( "cf stop testAppName-old &>" ) ) )
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
2018-11-27 12:47:44 +02:00
}
2020-02-07 19:46:03 +02:00
@Test
void testCfNativeBlueGreenMultipleApplications ( ) {
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName1'},{name: 'manifestAppName2'}]" )
fileExistsRule . registerExistingFile ( 'test.yml' )
thrown . expect ( hudson . AbortException )
thrown . expectMessage ( "[cloudFoundryDeploy] Your manifest contains more than one application. For blue green deployments your manifest file may contain only one application." )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
}
@Test
void testCfNativeBlueGreenWithNoRoute ( ) {
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName1', no-route: true}]" )
fileExistsRule . registerExistingFile ( 'test.yml' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
}
2019-01-30 11:07:00 +02:00
@Test
void testCfNativeBlueGreenKeepOldInstanceShouldThrowErrorOnStopError ( ) {
new File ( tmpDir , '1-cfStopOutput.txt' ) . write ( 'any error message' )
2020-02-14 14:41:36 +02:00
helper . registerAllowedMethod ( "sh" , [ String ] , { cmd - >
if ( cmd . toString ( ) . contains ( 'cf stop testAppName-old' ) )
throw new Exception ( 'fail' )
} )
2019-01-30 11:07:00 +02:00
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2019-01-30 11:07:00 +02:00
thrown . expect ( hudson . AbortException )
2019-09-20 09:57:28 +02:00
thrown . expectMessage ( "[cloudFoundryDeploy] ERROR: Could not stop application testAppName-old. Error: any error message" )
2019-01-30 11:07:00 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
keepOldInstance: true ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-30 11:07:00 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf stop testAppName-old &> 1-cfStopOutput.txt" ) ) )
}
2018-11-27 12:47:44 +02:00
@Test
void testCfNativeStandardShouldNotStopInstance ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-11-27 12:47:44 +02:00
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-11-27 12:47:44 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-11-27 12:47:44 +02:00
deployTool: 'cf_native' ,
deployType: 'standard' ,
keepOldInstance: true ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-01-30 11:07:00 +02:00
assertThat ( shellRule . shell , not ( hasItem ( containsString ( "cf stop testAppName-old &>" ) ) ) )
2018-11-27 12:47:44 +02:00
}
2018-11-07 11:39:30 +02:00
@Test
void testCfNativeWithoutAppNameBlueGreen ( ) {
2019-09-24 08:49:25 +02:00
fileExistsRule . registerExistingFile ( 'test.yml' )
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{}]" )
2018-11-07 11:39:30 +02:00
thrown . expect ( hudson . AbortException )
thrown . expectMessage ( '[cloudFoundryDeploy] ERROR: Blue-green plugin requires app name to be passed (see https://github.com/bluemixgaragelondon/cf-blue-green-deploy/issues/27)' )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-11-07 11:39:30 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-11-07 11:39:30 +02:00
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfManifest: 'test.yml'
] )
}
2019-09-20 09:57:28 +02:00
@Test
void testCfNativeFailureInShellCall ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2019-09-20 09:57:28 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
2020-02-14 14:41:36 +02:00
helper . registerAllowedMethod ( "sh" , [ String ] , { cmd - >
if ( cmd . toString ( ) . contains ( 'cf login -u "test_cf"' ) )
throw new Exception ( 'fail' )
} )
2019-09-20 09:57:28 +02:00
thrown . expect ( hudson . AbortException )
thrown . expectMessage ( '[cloudFoundryDeploy] ERROR: The execution of the deploy command failed, see the log for details.' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
}
2018-11-07 11:39:30 +02:00
2018-07-30 09:28:24 +02:00
@Test
void testMta ( ) {
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2018-07-30 09:28:24 +02:00
script: nullScript ,
juStabUtils: utils ,
2019-01-18 09:25:22 +02:00
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
2018-07-30 09:28:24 +02:00
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
deployTool: 'mtaDeployPlugin' ,
mtaPath: 'target/test.mtar'
] )
2018-08-29 10:01:16 +02:00
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-01-22 10:34:18 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
2019-10-22 13:53:08 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
2019-01-22 10:19:28 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf deploy target/test.mtar -f' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf logout' ) ) )
2018-07-30 09:28:24 +02:00
}
2019-01-18 09:25:22 +02:00
2019-01-22 17:13:59 +02:00
@Test
void testMtaBlueGreen ( ) {
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2019-01-22 17:13:59 +02:00
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
deployTool: 'mtaDeployPlugin' ,
deployType: 'blue-green' ,
mtaPath: 'target/test.mtar'
] )
2019-10-22 13:53:08 +02:00
assertThat ( shellRule . shell , hasItem ( stringContainsInOrder ( [ "cf login -u \"test_cf\"" , 'cf bg-deploy' , '-f' , '--no-confirm' ] ) ) )
2019-01-22 17:13:59 +02:00
}
2019-01-18 09:25:22 +02:00
@Test
void testInfluxReporting ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2019-01-18 09:25:22 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
nullScript . commonPipelineEnvironment . setArtifactVersion ( '1.2.3' )
2019-01-22 10:25:42 +02:00
stepRule . step . cloudFoundryDeploy ( [
2019-01-18 09:25:22 +02:00
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
// asserts
assertThat ( writeInfluxMap . customDataMap . deployment_data . artifactUrl , is ( 'n/a' ) )
assertThat ( writeInfluxMap . customDataMap . deployment_data . deployTime , containsString ( new Date ( ) . format ( 'MMM dd, yyyy' ) ) )
assertThat ( writeInfluxMap . customDataMap . deployment_data . jobTrigger , is ( 'USER' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . artifactVersion , is ( '1.2.3' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . deployUser , is ( 'test_cf' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . deployResult , is ( 'SUCCESS' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . cfApiEndpoint , is ( 'https://api.cf.eu10.hana.ondemand.com' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . cfOrg , is ( 'testOrg' ) )
assertThat ( writeInfluxMap . customDataMapTags . deployment_data . cfSpace , is ( 'testSpace' ) )
}
2019-09-24 08:49:25 +02:00
@Test
void testCfPushDeploymentWithVariableSubstitutionFromFile ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-09-24 08:49:25 +02:00
fileExistsRule . registerExistingFile ( 'test.yml' )
fileExistsRule . registerExistingFile ( 'vars.yml' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariablesFiles: [ 'vars.yml' ]
] )
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName --vars-file 'vars.yml' -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
assertThat ( loggingRule . log , containsString ( "We will add the following string to the cf push call: --vars-file 'vars.yml' !" ) )
assertThat ( loggingRule . log , not ( containsString ( "We will add the following string to the cf push call: !" ) ) )
}
@Test
void testCfPushDeploymentWithVariableSubstitutionFromNotExistingFilePrintsWarning ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-10-25 17:49:54 +02:00
fileExistsRule . registerExistingFile ( 'test.yml' )
2019-09-24 08:49:25 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariablesFiles: [ 'vars.yml' ]
] )
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
2019-09-24 08:49:25 +02:00
assertThat ( loggingRule . log , containsString ( "[WARNING] We skip adding not-existing file 'vars.yml' as a vars-file to the cf create-service-push call" ) )
}
@Test
void testCfPushDeploymentWithVariableSubstitutionFromVarsList ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-10-25 17:49:54 +02:00
List varsList = [ [ "appName" : "testApplicationFromVarsList" ] ]
2019-09-24 08:49:25 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariables: varsList
] )
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName --var appName='testApplicationFromVarsList' -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
assertThat ( loggingRule . log , containsString ( "We will add the following string to the cf push call: --var appName='testApplicationFromVarsList' !" ) )
assertThat ( loggingRule . log , not ( containsString ( "We will add the following string to the cf push call: !" ) ) )
}
@Test
void testCfPushDeploymentWithVariableSubstitutionFromVarsListNotAList ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-10-25 17:49:54 +02:00
2019-09-24 08:49:25 +02:00
thrown . expect ( hudson . AbortException )
thrown . expectMessage ( '[cloudFoundryDeploy] ERROR: Parameter config.cloudFoundry.manifestVariables is not a List!' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariables: 'notAList'
] )
2019-10-25 17:49:54 +02:00
2019-09-24 08:49:25 +02:00
}
@Test
void testCfPushDeploymentWithVariableSubstitutionFromVarsListAndVarsFile ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-09-24 08:49:25 +02:00
List varsList = [ [ "appName" : "testApplicationFromVarsList" ] ]
fileExistsRule . registerExistingFile ( 'vars.yml' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariablesFiles: [ 'vars.yml' ] ,
cfManifestVariables: varsList
] )
// asserts
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName --var appName='testApplicationFromVarsList' --vars-file 'vars.yml' -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
}
@Test
void testCfPushDeploymentWithoutVariableSubstitution ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-09-24 08:49:25 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
2019-10-25 17:49:54 +02:00
// asserts
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf push testAppName -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
}
@Test
void testCfBlueGreenDeploymentWithVariableSubstitution ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-09-24 08:49:25 +02:00
readYamlRule . registerYaml ( 'vars.yml' , "[appName: 'testApplication']" )
fileExistsRule . registerExistingFile ( "test.yml" )
fileExistsRule . registerExistingFile ( "vars.yml" )
boolean testYamlWritten = false
def testYamlData = null
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map m - >
if ( m . file . equals ( "test.yml" ) ) {
testYamlWritten = true
testYamlData = m . data
}
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariablesFiles: [ 'vars.yml' ]
] )
// asserts
assertTrue ( testYamlWritten )
assertNotNull ( testYamlData )
2020-02-07 19:46:03 +02:00
assertThat ( testYamlData . get ( "applications" ) . get ( 0 ) . get ( "name" ) , is ( "testApplication" ) )
2019-09-24 08:49:25 +02:00
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
}
@Test
void testCfBlueGreenDeploymentWithVariableSubstitutionFromVarsList ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: '((appName))'}]" )
2019-09-24 08:49:25 +02:00
readYamlRule . registerYaml ( 'vars.yml' , "[appName: 'testApplication']" )
List varsList = [ [ "appName" : "testApplicationFromVarsList" ] ]
fileExistsRule . registerExistingFile ( "test.yml" )
fileExistsRule . registerExistingFile ( "vars.yml" )
boolean testYamlWritten = false
def testYamlData = null
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map m - >
if ( m . file . equals ( "test.yml" ) ) {
testYamlWritten = true
testYamlData = m . data
}
} )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
deployType: 'blue-green' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml' ,
cfManifestVariablesFiles: [ 'vars.yml' ] ,
cfManifestVariables: varsList
] )
// asserts
assertTrue ( testYamlWritten )
assertNotNull ( testYamlData )
2020-02-07 19:46:03 +02:00
assertThat ( testYamlData . get ( "applications" ) . get ( 0 ) . get ( "name" ) , is ( "testApplicationFromVarsList" ) )
2019-09-24 08:49:25 +02:00
2019-10-25 17:49:54 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerImage' , 'ppiper/cf-cli' ) )
2019-09-24 08:49:25 +02:00
assertThat ( dockerExecuteRule . dockerParams , hasEntry ( 'dockerWorkspace' , '/home/piper' ) )
assertThat ( dockerExecuteRule . dockerParams . dockerEnvVars , hasEntry ( 'STATUS_CODE' , "${200}" ) )
assertThat ( shellRule . shell , hasItem ( containsString ( 'cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"' ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'" ) ) )
assertThat ( shellRule . shell , hasItem ( containsString ( "cf logout" ) ) )
}
2019-09-27 16:10:43 +02:00
@Test
void testTraceOutputOnVerbose ( ) {
fileExistsRule . existingFiles . addAll (
'test.yml' ,
'cf.log'
)
new File ( tmpDir , 'cf.log' ) < < 'Hello SAP'
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2019-09-27 16:10:43 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
manifest: 'test.yml' ,
] ,
cfCredentialsId: 'test_cfCredentialsId' ,
verbose: true
] )
assertThat ( loggingRule . log , allOf (
containsString ( '### START OF CF CLI TRACE OUTPUT ###' ) ,
containsString ( 'Hello SAP' ) ,
containsString ( '### END OF CF CLI TRACE OUTPUT ###' ) ) )
}
@Test
void testTraceNoTraceFileWritten ( ) {
fileExistsRule . existingFiles . addAll (
'test.yml' ,
)
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2019-09-27 16:10:43 +02:00
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
manifest: 'test.yml' ,
] ,
cfCredentialsId: 'test_cfCredentialsId' ,
verbose: true
] )
assertThat ( loggingRule . log , containsString ( 'No trace file found' ) )
}
2019-10-02 13:28:54 +02:00
@Test
void testAdditionCfNativeOpts ( ) {
2020-02-07 19:46:03 +02:00
readYamlRule . registerYaml ( 'test.yml' , "applications: [{name: 'manifestAppName'}]" )
2019-10-02 13:28:54 +02:00
helper . registerAllowedMethod ( 'writeYaml' , [ Map ] , { Map parameters - >
generatedFile = parameters . file
data = parameters . data
} )
nullScript . commonPipelineEnvironment . setArtifactVersion ( '1.2.3' )
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
deployTool: 'cf_native' ,
cfOrg: 'testOrg' ,
cfSpace: 'testSpace' ,
loginParameters: '--some-login-opt value' ,
cfNativeDeployParameters: '--some-deploy-opt cf-value' ,
cfCredentialsId: 'test_cfCredentialsId' ,
cfAppName: 'testAppName' ,
cfManifest: 'test.yml'
] )
assertThat ( shellRule . shell , hasItem (
stringContainsInOrder ( [
'cf login ' , '--some-login-opt value' ,
'cf push' , '--some-deploy-opt cf-value' ] ) ) )
}
@Test
void testAdditionMtaOpts ( ) {
stepRule . step . cloudFoundryDeploy ( [
script: nullScript ,
juStabUtils: utils ,
jenkinsUtilsStub: new JenkinsUtilsMock ( ) ,
cloudFoundry: [
org: 'testOrg' ,
space: 'testSpace' ,
] ,
apiParameters: '--some-api-opt value' ,
loginParameters: '--some-login-opt value' ,
mtaDeployParameters: '--some-deploy-opt mta-value' ,
cfCredentialsId: 'test_cfCredentialsId' ,
deployTool: 'mtaDeployPlugin' ,
deployType: 'blue-green' ,
mtaPath: 'target/test.mtar'
] )
assertThat ( shellRule . shell , hasItem (
stringContainsInOrder ( [
'cf api' , '--some-api-opt value' ,
'cf login ' , '--some-login-opt value' ,
'cf bg-deploy' , '--some-deploy-opt mta-value' ] ) ) )
}
2018-07-30 09:28:24 +02:00
}