1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-03 13:21:41 +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:
Daniel Mieg 2021-11-16 09:32:09 +01:00 committed by GitHub
parent f9f0cbfd33
commit 50b36794b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 7 deletions

View File

@ -12,6 +12,9 @@ import util.Rules
import static org.hamcrest.Matchers.*
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 {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@ -66,4 +69,26 @@ class abapEnvironmentPipelineStageIntegrationTestsTest extends BasePiperTest {
assertThat(stepsCalled, hasItems('abapEnvironmentCreateSystem'))
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'))
}
}

View File

@ -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'))
}
}

View File

@ -39,13 +39,15 @@ void call(Map parameters = [:]) {
try {
abapEnvironmentCreateSystem(script: parameters.script, includeAddon: true)
} catch (Exception e) {
script.currentBuild.result = 'UNSTABLE'
}
if (config.confirmDeletion) {
input message: "Add-on product was installed successfully? Once you proceed, the test system will be deleted."
}
if (!config.debug) {
cloudFoundryDeleteService script: parameters.script
echo "Deployment test of add-on product failed."
throw e
} finally {
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
}
}
}

View File

@ -18,7 +18,9 @@ void call(Map parameters = [:]) {
def stageName = parameters.stageName?:env.STAGE_NAME
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
abapAddonAssemblyKitPublishTargetVector(script: parameters.script, targetVectorScope: 'P')
}
}