fix marking failed levels as yellow if there are > 1 levels to ignore failed (i.e. marked yellow)

merge-requests/1/merge
ansgarz 2 years ago
parent 5fd7ab588f
commit 7157dc57dd

@ -374,8 +374,9 @@ open class Prov protected constructor(
successPerLevel.add(successOfCurrentLevel) successPerLevel.add(successOfCurrentLevel)
} }
val successOfLevelAbove = if (currentLevel == 0) successOfCurrentLevel else successPerLevel[currentLevel - 1] // check success levels above; if a level above succeeded then a failure in this level will be considered optional (i.e. marked yellow instead of red)
println(result.toString().escapeControlChars().formattedAsResultLine(successOfLevelAbove)) val successOfLevelsAbove = levelsAboveContainsSuccess(successPerLevel, currentLevel)
println(result.toString().escapeControlChars().formattedAsResultLine(successOfLevelsAbove))
} }
if (internalResults.size > 1) { if (internalResults.size > 1) {
println("----------------------------------------------------------------------------------------------------- ") println("----------------------------------------------------------------------------------------------------- ")
@ -384,6 +385,14 @@ open class Prov protected constructor(
println("============================================ SUMMARY END ============================================ " + newline()) println("============================================ SUMMARY END ============================================ " + newline())
} }
private fun levelsAboveContainsSuccess(successPerLevel: ArrayList<Boolean>, currentLevel: Int): Boolean {
var success = false
for (i in 0..currentLevel - 1) {
success = success || successPerLevel[i]
}
return success
}
private fun String.formattedAsResultLine(showFailedInYellow: Boolean = false): String { private fun String.formattedAsResultLine(showFailedInYellow: Boolean = false): String {
val failedColor = if (showFailedInYellow) ANSI_BRIGHT_YELLOW else ANSI_BRIGHT_RED val failedColor = if (showFailedInYellow) ANSI_BRIGHT_YELLOW else ANSI_BRIGHT_RED
return this return this

@ -355,7 +355,7 @@ internal class ProvTest {
@Test @Test
@NonCi @NonCi
fun prov_prints_correct_output_for_failure_that_is_not_taken_into_account() { fun prov_marks_failed_output_yellow_if_optional() {
// given // given
setRootLoggingLevel(Level.OFF) setRootLoggingLevel(Level.OFF)
@ -369,11 +369,14 @@ internal class ProvTest {
System.setErr(PrintStream(errContent)) System.setErr(PrintStream(errContent))
// when // when
Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE).requireLast { Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE).task("taskA") {
checkPrereq_evaluateToFailure() optional {
task("returns success") { taskWithResult("taskB") {
ProvResult(true) taskWithResult("taskC") {
} ProvResult(false)
}
}
}
} }
// then // then
@ -384,9 +387,10 @@ internal class ProvTest {
val expectedOutput = val expectedOutput =
"============================================== SUMMARY (test instance with no progress info) ============================================== \n" + "============================================== SUMMARY (test instance with no progress info) ============================================== \n" +
"> \u001B[92mSuccess\u001B[0m -- prov_prints_correct_output_for_failure_that_is_not_taken_into_account (requireLast) \n" + "> \u001B[92mSuccess\u001B[0m -- taskA \n" +
"---> \u001B[93mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + "---> \u001B[92mSuccess\u001B[0m -- prov_marks_failed_output_yellow_if_optional (optional) \n" +
"---> \u001B[92mSuccess\u001B[0m -- returns success \n" + "------> \u001B[93mFAILED\u001B[0m -- taskB \n" +
"---------> \u001B[93mFAILED\u001B[0m -- taskC \n" +
"----------------------------------------------------------------------------------------------------- \n" + "----------------------------------------------------------------------------------------------------- \n" +
"Overall > \u001B[92mSuccess\u001B[0m\n" + "Overall > \u001B[92mSuccess\u001B[0m\n" +
"============================================ SUMMARY END ============================================ \n" + "============================================ SUMMARY END ============================================ \n" +

@ -2,13 +2,13 @@ package org.domaindrivenarchitecture.provs.framework.ubuntu.keys
import org.domaindrivenarchitecture.provs.framework.core.Secret import org.domaindrivenarchitecture.provs.framework.core.Secret
import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.domaindrivenarchitecture.provs.test.tags.NonCi import org.domaindrivenarchitecture.provs.test.tags.NonCi
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
internal class ProvisionKeysTest { internal class ProvisionKeysTest {
@Test @ContainerTest
@NonCi @NonCi
fun provisionKeys() { fun provisionKeys() {
// given // given

Loading…
Cancel
Save