2017-07-11 15:12:03 +02:00
|
|
|
import hudson.AbortException
|
|
|
|
import org.junit.rules.TemporaryFolder
|
|
|
|
|
|
|
|
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
|
|
|
|
|
|
|
import static ProjectSource.projectSource
|
|
|
|
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
|
2017-11-13 16:56:19 +02:00
|
|
|
class NeoDeploymentTest extends PiperTestBase {
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public ExpectedException thrown = new ExpectedException().none()
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public TemporaryFolder tmp = new TemporaryFolder()
|
|
|
|
|
|
|
|
def archivePath
|
|
|
|
|
|
|
|
@Before
|
|
|
|
void setup() {
|
|
|
|
|
2017-11-13 16:56:19 +02:00
|
|
|
super._setUp()
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
archivePath = "${tmp.newFolder("workspace").toURI().getPath()}archiveName.mtar"
|
|
|
|
|
|
|
|
helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) })
|
|
|
|
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
|
|
|
|
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
|
|
|
if(l[0].credentialsId == 'myCredentialsId') {
|
|
|
|
binding.setProperty('username', 'anonymous')
|
|
|
|
binding.setProperty('password', '********')
|
|
|
|
} else if(l[0].credentialsId == 'CI_CREDENTIALS_ID') {
|
|
|
|
binding.setProperty('username', 'defaultUser')
|
|
|
|
binding.setProperty('password', '********')
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
c()
|
|
|
|
} finally {
|
|
|
|
binding.setProperty('username', null)
|
|
|
|
binding.setProperty('password', null)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
binding.setVariable('env', [:])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void straightForwardTest() {
|
|
|
|
|
|
|
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-13 11:26:19 +02:00
|
|
|
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-14 12:00:52 +02:00
|
|
|
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void badCredentialsIdTest() {
|
|
|
|
|
|
|
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
|
|
|
thrown.expect(MissingPropertyException)
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(defaultPipeline()).execute(archivePath, 'badCredentialsId')
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void credentialsIdNotProvidedTest() {
|
|
|
|
|
|
|
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-13 11:26:19 +02:00
|
|
|
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-14 12:00:52 +02:00
|
|
|
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void neoHomeNotSetTest() {
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-13 11:26:19 +02:00
|
|
|
assert shellCalls[0] =~ /#!\/bin\/bash neo deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-14 12:00:52 +02:00
|
|
|
assert messages[1] == "Using Neo executable from PATH."
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void neoHomeAsParameterTest() {
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(neoHomeParameterPipeline()).execute(archivePath, 'myCredentialsId')
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-13 11:26:19 +02:00
|
|
|
assert shellCalls[0] =~ /#!\/bin\/bash \/etc\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-14 12:00:52 +02:00
|
|
|
assert messages[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters."
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void archiveNotProvidedTest() {
|
|
|
|
|
|
|
|
thrown.expect(Exception)
|
|
|
|
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(noArchivePathPipeline()).execute()
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void wrongArchivePathProvidedTest() {
|
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void scriptNotProvidedTest() {
|
|
|
|
|
|
|
|
new File(archivePath) << "dummy archive"
|
|
|
|
|
|
|
|
thrown.expect(Exception)
|
|
|
|
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
|
|
|
|
2017-11-14 13:57:16 +02:00
|
|
|
withPipeline(noScriptPipeline()).execute(archivePath)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private defaultPipeline(){
|
2017-11-16 15:09:48 +02:00
|
|
|
{ -> """
|
|
|
|
@Library('piper-library-os')
|
|
|
|
|
|
|
|
execute(archivePath, neoCredentialsId) {
|
|
|
|
|
|
|
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
|
|
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
|
|
|
|
|
|
|
node() {
|
|
|
|
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
"""}
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private noCredentialsIdPipeline(){
|
2017-11-16 15:09:48 +02:00
|
|
|
{ -> """
|
|
|
|
@Library('piper-library-os')
|
|
|
|
|
|
|
|
execute(archivePath) {
|
|
|
|
|
|
|
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
|
|
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
|
|
|
|
|
|
|
node() {
|
|
|
|
neoDeploy script: this, archivePath: archivePath
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
""" }
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private neoHomeParameterPipeline(){
|
2017-11-16 15:09:48 +02:00
|
|
|
{ -> """
|
|
|
|
@Library('piper-library-os')
|
|
|
|
|
|
|
|
execute(archivePath, neoCredentialsId) {
|
|
|
|
|
|
|
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
|
|
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
|
|
|
|
|
|
|
node() {
|
|
|
|
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId, neoHome: '/etc/neo'
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
""" }
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private noArchivePathPipeline(){
|
2017-11-14 13:57:16 +02:00
|
|
|
{ -> """
|
2017-11-16 15:09:48 +02:00
|
|
|
@Library('piper-library-os')
|
|
|
|
|
|
|
|
execute() {
|
|
|
|
|
|
|
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
|
|
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
|
|
|
|
|
|
|
node() {
|
|
|
|
neoDeploy script: this
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
""" }
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private noScriptPipeline(){
|
2017-11-16 15:09:48 +02:00
|
|
|
{ -> """
|
|
|
|
@Library('piper-library-os')
|
|
|
|
|
|
|
|
execute(archivePath) {
|
|
|
|
|
|
|
|
node() {
|
|
|
|
neoDeploy archivePath: archivePath
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
""" }
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|