mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-09 13:47:31 +02:00
Fail properly in Integration Tests (#3282)
* Require success for publish * Echo and tets * Fix test * Improve test * Update docu * Let Integration Test throw * Update publish.md * Remove condition for publish * Update docu
This commit is contained in:
parent
f9f0cbfd33
commit
50b36794b1
@ -12,6 +12,9 @@ import util.Rules
|
|||||||
|
|
||||||
import static org.hamcrest.Matchers.*
|
import static org.hamcrest.Matchers.*
|
||||||
import static org.junit.Assert.assertThat
|
import static org.junit.Assert.assertThat
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.junit.Assert.fail
|
||||||
|
|
||||||
class abapEnvironmentPipelineStageIntegrationTestsTest extends BasePiperTest {
|
class abapEnvironmentPipelineStageIntegrationTestsTest extends BasePiperTest {
|
||||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||||
@ -66,4 +69,26 @@ class abapEnvironmentPipelineStageIntegrationTestsTest extends BasePiperTest {
|
|||||||
assertThat(stepsCalled, hasItems('abapEnvironmentCreateSystem'))
|
assertThat(stepsCalled, hasItems('abapEnvironmentCreateSystem'))
|
||||||
assertThat(stepsCalled, hasItems('cloudFoundryDeleteService'))
|
assertThat(stepsCalled, hasItems('cloudFoundryDeleteService'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCreateSystemFails() {
|
||||||
|
|
||||||
|
helper.registerAllowedMethod('abapEnvironmentCreateSystem', [Map.class], {m -> stepsCalled.add('abapEnvironmentCreateSystem'); error("Failed")})
|
||||||
|
|
||||||
|
nullScript.commonPipelineEnvironment.configuration.runStage = [
|
||||||
|
'Integration Tests': true
|
||||||
|
]
|
||||||
|
|
||||||
|
try {
|
||||||
|
jsr.step.abapEnvironmentPipelineStageIntegrationTests(script: nullScript, confirmDeletion: false)
|
||||||
|
fail("Expected exception")
|
||||||
|
} catch (Exception e) {
|
||||||
|
// failure expected
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(stepsCalled, not(hasItem('input')))
|
||||||
|
assertThat(stepsCalled, hasItems('abapEnvironmentCreateSystem'))
|
||||||
|
assertThat(stepsCalled, hasItems('cloudFoundryDeleteService'))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package templates
|
||||||
|
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.rules.RuleChain
|
||||||
|
import util.BasePiperTest
|
||||||
|
import util.JenkinsReadYamlRule
|
||||||
|
import util.JenkinsStepRule
|
||||||
|
import util.PipelineWhenException
|
||||||
|
import util.Rules
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*
|
||||||
|
import static org.junit.Assert.assertThat
|
||||||
|
|
||||||
|
class abapEnvironmentPipelineStagePublishTest extends BasePiperTest {
|
||||||
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public RuleChain rules = Rules
|
||||||
|
.getCommonRules(this)
|
||||||
|
.around(new JenkinsReadYamlRule(this))
|
||||||
|
.around(jsr)
|
||||||
|
|
||||||
|
private stepsCalled = []
|
||||||
|
|
||||||
|
@Before
|
||||||
|
void init() {
|
||||||
|
binding.variables.env.STAGE_NAME = 'Publish'
|
||||||
|
|
||||||
|
helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
|
||||||
|
assertThat(m.stageName, is('Publish'))
|
||||||
|
return body()
|
||||||
|
})
|
||||||
|
helper.registerAllowedMethod('input', [Map], {m ->
|
||||||
|
stepsCalled.add('input')
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
helper.registerAllowedMethod('abapAddonAssemblyKitPublishTargetVector', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitPublishTargetVector')})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPublishExecuted() {
|
||||||
|
|
||||||
|
nullScript.commonPipelineEnvironment.configuration.runStage = []
|
||||||
|
|
||||||
|
jsr.step.abapEnvironmentPipelineStagePublish(script: nullScript)
|
||||||
|
|
||||||
|
assertThat(stepsCalled, hasItem('abapAddonAssemblyKitPublishTargetVector'))
|
||||||
|
}
|
||||||
|
}
|
@ -39,13 +39,15 @@ void call(Map parameters = [:]) {
|
|||||||
try {
|
try {
|
||||||
abapEnvironmentCreateSystem(script: parameters.script, includeAddon: true)
|
abapEnvironmentCreateSystem(script: parameters.script, includeAddon: true)
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
script.currentBuild.result = 'UNSTABLE'
|
echo "Deployment test of add-on product failed."
|
||||||
}
|
throw e
|
||||||
if (config.confirmDeletion) {
|
} finally {
|
||||||
input message: "Add-on product was installed successfully? Once you proceed, the test system will be deleted."
|
if (config.confirmDeletion) {
|
||||||
}
|
input message: "Deployment test has been executed. Once you proceed, the test system will be deleted."
|
||||||
if (!config.debug) {
|
}
|
||||||
cloudFoundryDeleteService script: parameters.script
|
if (!config.debug) {
|
||||||
|
cloudFoundryDeleteService script: parameters.script
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ void call(Map parameters = [:]) {
|
|||||||
def stageName = parameters.stageName?:env.STAGE_NAME
|
def stageName = parameters.stageName?:env.STAGE_NAME
|
||||||
|
|
||||||
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
|
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
|
||||||
|
|
||||||
abapAddonAssemblyKitPublishTargetVector(script: parameters.script, targetVectorScope: 'P')
|
abapAddonAssemblyKitPublishTargetVector(script: parameters.script, targetVectorScope: 'P')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user