mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
commit
a72cd278b4
@ -23,7 +23,7 @@ class FileUtilsTest {
|
|||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
void setup() {
|
void setUp() {
|
||||||
|
|
||||||
emptyDir = tmp.newFolder('emptyDir')
|
emptyDir = tmp.newFolder('emptyDir')
|
||||||
notEmptyDir = tmp.newFolder('notEmptyDir')
|
notEmptyDir = tmp.newFolder('notEmptyDir')
|
||||||
|
@ -5,15 +5,10 @@ import org.junit.Before
|
|||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
|
|
||||||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
public class MTABuildTest extends PiperTestBase {
|
||||||
|
|
||||||
import static ProjectSource.projectSource
|
|
||||||
|
|
||||||
public class MTABuildTest extends BasePipelineTest {
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = new ExpectedException()
|
public ExpectedException thrown = new ExpectedException()
|
||||||
@ -21,34 +16,18 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder tmp = new TemporaryFolder()
|
public TemporaryFolder tmp = new TemporaryFolder()
|
||||||
|
|
||||||
def shellCalls = []
|
|
||||||
def echoes = []
|
|
||||||
def currentDir
|
def currentDir
|
||||||
def otherDir
|
def otherDir
|
||||||
def pipeline
|
|
||||||
def mtaBuildShEnv
|
def mtaBuildShEnv
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup(){
|
void setUp() {
|
||||||
super.setUp()
|
|
||||||
|
|
||||||
|
super.setUp()
|
||||||
currentDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
currentDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
||||||
otherDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
otherDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
||||||
pipeline = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline"
|
|
||||||
|
|
||||||
def piperLib = library()
|
|
||||||
.name('piper-library-os')
|
|
||||||
.retriever(projectSource())
|
|
||||||
.targetPath('clonePath/is/not/necessary')
|
|
||||||
.defaultVersion('<irrelevant>')
|
|
||||||
.allowOverride(true)
|
|
||||||
.implicit(false)
|
|
||||||
.build()
|
|
||||||
helper.registerSharedLibrary(piperLib)
|
|
||||||
|
|
||||||
helper.registerAllowedMethod('sh', [String], {s -> shellCalls.add(s)} )
|
|
||||||
helper.registerAllowedMethod('echo', [String], {s -> echoes.add(s)} )
|
|
||||||
helper.registerAllowedMethod('readYaml', [Map], {
|
helper.registerAllowedMethod('readYaml', [Map], {
|
||||||
m ->
|
m ->
|
||||||
return new Yaml().load((m.file as File).text)
|
return new Yaml().load((m.file as File).text)
|
||||||
@ -80,9 +59,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
defaultPipeline()
|
def mtarFilePath = withPipeline(defaultPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
def mtarFilePath = script.execute()
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||||
|
|
||||||
@ -92,7 +69,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||||
|
|
||||||
assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,9 +80,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
returnMtarFilePathFromCommonPipelineEnvironmentPipeline()
|
def mtarFilePath = withPipeline(returnMtarFilePathFromCommonPipelineEnvironmentPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
def mtarFilePath = script.execute()
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||||
|
|
||||||
@ -115,7 +90,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||||
|
|
||||||
assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,9 +103,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
new File("${currentDir}/${newDirName}").mkdirs()
|
new File("${currentDir}/${newDirName}").mkdirs()
|
||||||
new File("${currentDir}/${newDirName}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/${newDirName}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
withSurroundingDirPipeline()
|
def mtarFilePath = withPipeline(withSurroundingDirPipeline()).execute(newDirName)
|
||||||
def script = loadScript(pipeline)
|
|
||||||
def mtarFilePath = script.execute(newDirName)
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
||||||
|
|
||||||
@ -140,7 +113,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||||
|
|
||||||
assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -148,9 +121,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
defaultPipeline()
|
def mtarFilePath = withPipeline(defaultPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
def mtarFilePath = script.execute()
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||||
|
|
||||||
@ -160,7 +131,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||||
|
|
||||||
assert echoes[1] == "[mtaBuild] Using MTA JAR from current working directory."
|
assert messages[1] == "[mtaBuild] Using MTA JAR from current working directory."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,9 +140,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
mtaJarLocationAsParameterPipeline()
|
def mtarFilePath = withPipeline(mtaJarLocationAsParameterPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
def mtarFilePath = script.execute()
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||||
|
|
||||||
@ -181,7 +150,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||||
|
|
||||||
assert echoes[1] == "[mtaBuild] MTA JAR \"/etc/mta/mta.jar\" retrieved from parameters."
|
assert messages[1] == "[mtaBuild] MTA JAR \"/etc/mta/mta.jar\" retrieved from parameters."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -189,9 +158,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
public void noMtaPresentTest(){
|
public void noMtaPresentTest(){
|
||||||
thrown.expect(FileNotFoundException)
|
thrown.expect(FileNotFoundException)
|
||||||
|
|
||||||
defaultPipeline()
|
withPipeline(defaultPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
script.execute()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,9 +169,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << badMtaYaml()
|
new File("${currentDir}/mta.yaml") << badMtaYaml()
|
||||||
|
|
||||||
defaultPipeline()
|
withPipeline(defaultPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
script.execute()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,9 +180,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << noIdMtaYaml()
|
new File("${currentDir}/mta.yaml") << noIdMtaYaml()
|
||||||
|
|
||||||
defaultPipeline()
|
withPipeline(defaultPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
script.execute()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -228,74 +191,71 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
|
|
||||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||||
|
|
||||||
noBuildTargetPipeline()
|
withPipeline(noBuildTargetPipeline()).execute()
|
||||||
def script = loadScript(pipeline)
|
|
||||||
script.execute()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private defaultPipeline(){
|
private defaultPipeline(){
|
||||||
new File(pipeline) << '''
|
return '''
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(){
|
execute(){
|
||||||
mtaBuild buildTarget: 'NEO'
|
mtaBuild buildTarget: 'NEO'
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
private returnMtarFilePathFromCommonPipelineEnvironmentPipeline(){
|
private returnMtarFilePathFromCommonPipelineEnvironmentPipeline(){
|
||||||
new File(pipeline) << '''
|
return '''
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(){
|
execute(){
|
||||||
mtaBuild buildTarget: 'NEO'
|
mtaBuild buildTarget: 'NEO'
|
||||||
return commonPipelineEnvironment.getMtarFilePath()
|
return commonPipelineEnvironment.getMtarFilePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
private mtaJarLocationAsParameterPipeline(){
|
private mtaJarLocationAsParameterPipeline(){
|
||||||
new File(pipeline) << '''
|
return '''
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(){
|
execute(){
|
||||||
mtaBuild mtaJarLocation: '/etc/mta', buildTarget: 'NEO'
|
mtaBuild mtaJarLocation: '/etc/mta', buildTarget: 'NEO'
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
private withSurroundingDirPipeline(){
|
private withSurroundingDirPipeline(){
|
||||||
new File(pipeline) << '''
|
return '''
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(dirPath){
|
execute(dirPath){
|
||||||
dir("${dirPath}"){
|
dir("${dirPath}"){
|
||||||
mtaBuild buildTarget: 'NEO'
|
mtaBuild buildTarget: 'NEO'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private noBuildTargetPipeline(){
|
private noBuildTargetPipeline(){
|
||||||
new File(pipeline) << '''
|
return '''
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(){
|
execute(){
|
||||||
mtaBuild()
|
mtaBuild()
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,10 +10,7 @@ import org.junit.Rule
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
|
|
||||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
class NeoDeploymentTest extends PiperTestBase {
|
||||||
|
|
||||||
|
|
||||||
class NeoDeploymentTest extends BasePipelineTest {
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = new ExpectedException().none()
|
public ExpectedException thrown = new ExpectedException().none()
|
||||||
@ -21,37 +18,16 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder tmp = new TemporaryFolder()
|
public TemporaryFolder tmp = new TemporaryFolder()
|
||||||
|
|
||||||
def script
|
|
||||||
|
|
||||||
def shellCalls = []
|
|
||||||
|
|
||||||
def pipeline
|
|
||||||
def echoes = []
|
|
||||||
def archivePath
|
def archivePath
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
void setup() {
|
void setUp() {
|
||||||
|
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|
||||||
archivePath = "${tmp.newFolder("workspace").toURI().getPath()}archiveName.mtar"
|
archivePath = "${tmp.newFolder("workspace").toURI().getPath()}archiveName.mtar"
|
||||||
pipeline = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline"
|
|
||||||
|
|
||||||
def piperLib = library()
|
|
||||||
.name('piper-library-os')
|
|
||||||
.retriever(projectSource())
|
|
||||||
.targetPath('clonePath/is/not/necessary')
|
|
||||||
.defaultVersion('irrelevant')
|
|
||||||
.allowOverride(true)
|
|
||||||
.implicit(false)
|
|
||||||
.build()
|
|
||||||
helper.registerSharedLibrary(piperLib)
|
|
||||||
|
|
||||||
helper.registerAllowedMethod('sh', [String], { GString s ->
|
|
||||||
shellCalls.add(s.replaceAll(/\s+/, " ").trim())
|
|
||||||
})
|
|
||||||
helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) })
|
helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) })
|
||||||
helper.registerAllowedMethod('echo', [String], { s -> echoes.add(s) })
|
|
||||||
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
|
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
|
||||||
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
||||||
if(l[0].credentialsId == 'myCredentialsId') {
|
if(l[0].credentialsId == 'myCredentialsId') {
|
||||||
@ -78,19 +54,15 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void straightForwardTest() {
|
void straightForwardTest() {
|
||||||
|
|
||||||
defaultPipeline()
|
|
||||||
|
|
||||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
||||||
|
|
||||||
script.execute(archivePath, 'myCredentialsId')
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
||||||
|
|
||||||
assert echoes[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,17 +70,13 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void badCredentialsIdTest() {
|
void badCredentialsIdTest() {
|
||||||
|
|
||||||
defaultPipeline()
|
|
||||||
|
|
||||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
thrown.expect(MissingPropertyException)
|
thrown.expect(MissingPropertyException)
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(defaultPipeline()).execute(archivePath, 'badCredentialsId')
|
||||||
|
|
||||||
script.execute(archivePath, 'badCredentialsId')
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,53 +84,41 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void credentialsIdNotProvidedTest() {
|
void credentialsIdNotProvidedTest() {
|
||||||
|
|
||||||
noCredentialsIdPipeline()
|
|
||||||
|
|
||||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
||||||
|
|
||||||
script.execute(archivePath)
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
||||||
|
|
||||||
assert echoes[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void neoHomeNotSetTest() {
|
void neoHomeNotSetTest() {
|
||||||
|
|
||||||
noCredentialsIdPipeline()
|
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
||||||
|
|
||||||
script.execute(archivePath)
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /#!\/bin\/bash neo deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
assert shellCalls[0] =~ /#!\/bin\/bash neo deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
||||||
|
|
||||||
assert echoes[1] == "Using Neo executable from PATH."
|
assert messages[1] == "Using Neo executable from PATH."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void neoHomeAsParameterTest() {
|
void neoHomeAsParameterTest() {
|
||||||
|
|
||||||
neoHomeParameterPipeline()
|
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(neoHomeParameterPipeline()).execute(archivePath, 'myCredentialsId')
|
||||||
|
|
||||||
script.execute(archivePath, 'myCredentialsId')
|
|
||||||
|
|
||||||
assert shellCalls[0] =~ /#!\/bin\/bash \/etc\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
assert shellCalls[0] =~ /#!\/bin\/bash \/etc\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/
|
||||||
|
|
||||||
assert echoes[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters."
|
assert messages[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters."
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,14 +126,10 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void archiveNotProvidedTest() {
|
void archiveNotProvidedTest() {
|
||||||
|
|
||||||
noArchivePathPipeline()
|
|
||||||
|
|
||||||
thrown.expect(Exception)
|
thrown.expect(Exception)
|
||||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(noArchivePathPipeline()).execute()
|
||||||
|
|
||||||
script.execute()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,14 +137,10 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void wrongArchivePathProvidedTest() {
|
void wrongArchivePathProvidedTest() {
|
||||||
|
|
||||||
defaultPipeline()
|
|
||||||
|
|
||||||
thrown.expect(AbortException)
|
thrown.expect(AbortException)
|
||||||
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
||||||
|
|
||||||
script.execute(archivePath, 'myCredentialsId')
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,110 +148,106 @@ class NeoDeploymentTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void scriptNotProvidedTest() {
|
void scriptNotProvidedTest() {
|
||||||
|
|
||||||
noScriptPipeline()
|
|
||||||
|
|
||||||
new File(archivePath) << "dummy archive"
|
new File(archivePath) << "dummy archive"
|
||||||
|
|
||||||
thrown.expect(Exception)
|
thrown.expect(Exception)
|
||||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
||||||
|
|
||||||
script = loadScript(pipeline)
|
withPipeline(noScriptPipeline()).execute(archivePath)
|
||||||
|
|
||||||
script.execute(archivePath)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private defaultPipeline(){
|
private defaultPipeline(){
|
||||||
new File(pipeline) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(archivePath, neoCredentialsId) {
|
execute(archivePath, neoCredentialsId) {
|
||||||
|
|
||||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId
|
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private noCredentialsIdPipeline(){
|
private noCredentialsIdPipeline(){
|
||||||
new File(pipeline) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(archivePath) {
|
execute(archivePath) {
|
||||||
|
|
||||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
neoDeploy script: this, archivePath: archivePath
|
neoDeploy script: this, archivePath: archivePath
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private neoHomeParameterPipeline(){
|
private neoHomeParameterPipeline(){
|
||||||
new File(pipeline) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(archivePath, neoCredentialsId) {
|
execute(archivePath, neoCredentialsId) {
|
||||||
|
|
||||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId, neoHome: '/etc/neo'
|
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId, neoHome: '/etc/neo'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private noArchivePathPipeline(){
|
private noArchivePathPipeline(){
|
||||||
new File(pipeline) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
|
|
||||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
neoDeploy script: this
|
neoDeploy script: this
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private noScriptPipeline(){
|
private noScriptPipeline(){
|
||||||
new File(pipeline) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute(archivePath) {
|
execute(archivePath) {
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
neoDeploy archivePath: archivePath
|
neoDeploy archivePath: archivePath
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
51
test/groovy/PiperTestBase.groovy
Normal file
51
test/groovy/PiperTestBase.groovy
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||||
|
|
||||||
|
import static ProjectSource.projectSource
|
||||||
|
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
||||||
|
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.rules.TemporaryFolder
|
||||||
|
|
||||||
|
public class PiperTestBase extends BasePipelineTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder pipelineFolder = new TemporaryFolder()
|
||||||
|
|
||||||
|
private File pipeline
|
||||||
|
|
||||||
|
protected messages = [], shellCalls = []
|
||||||
|
|
||||||
|
void setUp() {
|
||||||
|
|
||||||
|
super.setUp()
|
||||||
|
|
||||||
|
messages.clear()
|
||||||
|
shellCalls.clear()
|
||||||
|
|
||||||
|
preparePiperLib()
|
||||||
|
|
||||||
|
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)} )
|
||||||
|
helper.registerAllowedMethod('sh', [String], { s ->
|
||||||
|
shellCalls.add(s.replaceAll(/\s+/, " ").trim())
|
||||||
|
})
|
||||||
|
|
||||||
|
pipeline = pipelineFolder.newFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected withPipeline(p) {
|
||||||
|
pipeline << p
|
||||||
|
loadScript(pipeline.toURI().getPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
private preparePiperLib() {
|
||||||
|
def piperLib = library()
|
||||||
|
.name('piper-library-os')
|
||||||
|
.retriever(projectSource())
|
||||||
|
.targetPath('clonePath/is/not/necessary')
|
||||||
|
.defaultVersion('<irrelevant>')
|
||||||
|
.allowOverride(true)
|
||||||
|
.implicit(false)
|
||||||
|
.build()
|
||||||
|
helper.registerSharedLibrary(piperLib)
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,3 @@
|
|||||||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
|
||||||
import static ProjectSource.projectSource
|
|
||||||
|
|
||||||
import org.apache.commons.exec.*
|
import org.apache.commons.exec.*
|
||||||
import hudson.AbortException
|
import hudson.AbortException
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@ -8,10 +5,8 @@ import org.junit.Rule
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
import org.junit.rules.ExpectedException
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
||||||
|
|
||||||
|
class ToolValidateTest extends PiperTestBase {
|
||||||
class ToolValidateTest extends BasePipelineTest {
|
|
||||||
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@ -21,31 +16,15 @@ class ToolValidateTest extends BasePipelineTest {
|
|||||||
public TemporaryFolder tmp = new TemporaryFolder()
|
public TemporaryFolder tmp = new TemporaryFolder()
|
||||||
|
|
||||||
private notEmptyDir
|
private notEmptyDir
|
||||||
private messages = []
|
|
||||||
private script
|
private script
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
void setup() {
|
void setUp() {
|
||||||
|
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|
||||||
def piperLib = library()
|
script = withPipeline(defaultPipeline())
|
||||||
.name('piper-library-os')
|
|
||||||
.retriever(projectSource())
|
|
||||||
.targetPath('clonePath/is/not/necessary')
|
|
||||||
.defaultVersion('irrelevant')
|
|
||||||
.allowOverride(true)
|
|
||||||
.implicit(false)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
helper.registerSharedLibrary(piperLib)
|
|
||||||
|
|
||||||
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)})
|
|
||||||
|
|
||||||
def pipelinePath = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline"
|
|
||||||
createPipeline(pipelinePath)
|
|
||||||
script = loadScript(pipelinePath)
|
|
||||||
|
|
||||||
notEmptyDir = tmp.newFolder('notEmptyDir')
|
notEmptyDir = tmp.newFolder('notEmptyDir')
|
||||||
def path = "${notEmptyDir.getAbsolutePath()}${File.separator}test.txt"
|
def path = "${notEmptyDir.getAbsolutePath()}${File.separator}test.txt"
|
||||||
@ -269,20 +248,20 @@ class ToolValidateTest extends BasePipelineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private createPipeline(pipelinePath){
|
private defaultPipeline(){
|
||||||
new File(pipelinePath) << """
|
return """
|
||||||
@Library('piper-library-os')
|
@Library('piper-library-os')
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
|
|
||||||
node() {
|
node() {
|
||||||
|
|
||||||
toolValidate tool: tool, home: home
|
toolValidate tool: tool, home: home
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private getNoVersion(Map m) {
|
private getNoVersion(Map m) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user