Skip to content

Commit b62e44a

Browse files
committed
Refactoring
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent 2d139b4 commit b62e44a

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

src/main/kotlin/com/salesforce/revoman/ReVoman.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ object ReVoman {
203203
envSnapshot =
204204
pm.environment.copy(mutableEnv = pm.environment.mutableEnv.toMutableMap())
205205
)
206-
// * NOTE 15/10/23 gopala.akshintala: http status code can be non-success
207-
haltExecution = shouldHaltExecution(currentStepReport, kick, pm)
206+
haltExecution = shouldHaltExecution(currentStepReport, kick, pm.rundown)
208207
stepReports + currentStepReport
209208
}
210209
}

src/main/kotlin/com/salesforce/revoman/input/config/KickDef.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal interface KickDef {
4848

4949
@Value.Default fun haltOnAnyFailure(): Boolean = false
5050

51-
fun haltOnFailureOfTypeExcept(): Map<ExeType, PostTxnStepPick>
51+
fun haltOnFailureOfTypeExcept(): Map<ExeType, PostTxnStepPick?>
5252

5353
fun runOnlySteps(): List<ExeStepPick>
5454

src/main/kotlin/com/salesforce/revoman/internal/exe/ExeUtils.kt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import arrow.core.Either.Left
1414
import arrow.core.Either.Right
1515
import com.salesforce.revoman.input.config.Kick
1616
import com.salesforce.revoman.input.config.StepPick.ExeStepPick
17-
import com.salesforce.revoman.internal.postman.PostmanSDK
1817
import com.salesforce.revoman.internal.postman.template.Item
1918
import com.salesforce.revoman.output.ExeType
19+
import com.salesforce.revoman.output.Rundown
20+
import com.salesforce.revoman.output.Rundown.Companion.isStepIgnoredForFailure
2021
import com.salesforce.revoman.output.report.Folder
2122
import com.salesforce.revoman.output.report.Step
2223
import com.salesforce.revoman.output.report.StepReport
@@ -91,10 +92,11 @@ internal fun <T> runCatching(
9192
)
9293
}
9394

95+
// ! TODO 01 Mar 2025 gopala.akshintala: Unit test this
9496
internal fun shouldHaltExecution(
9597
currentStepReport: StepReport,
9698
kick: Kick,
97-
pm: PostmanSDK,
99+
rundown: Rundown,
98100
): Boolean =
99101
when {
100102
currentStepReport.isSuccessful -> false
@@ -114,26 +116,15 @@ internal fun shouldHaltExecution(
114116
false
115117
}
116118
else ->
117-
kick
118-
.haltOnFailureOfTypeExcept()
119-
.asSequence()
120-
.any { (exeType, postTxnPick) ->
121-
currentStepReport.exeTypeForFailure == exeType &&
122-
postTxnPick.pick(
123-
currentStepReport,
124-
pm.rundown.copy(stepReports = pm.rundown.stepReports + currentStepReport),
125-
)
126-
}
127-
.not()
128-
.also {
129-
logger.info {
130-
if (it) {
131-
"${currentStepReport.step} doesn't qualify `haltOnFailureOfTypeExcept` for ${currentStepReport.exeTypeForFailure}, so 🛑 halting the execution of next steps"
132-
} else {
133-
"Continuing the execution of next steps, as the step qualifies `haltOnFailureOfTypeExcept` for ${currentStepReport.exeTypeForFailure}"
134-
}
119+
!isStepIgnoredForFailure(currentStepReport, rundown).also {
120+
logger.info {
121+
if (it) {
122+
"${currentStepReport.step} doesn't qualify `haltOnFailureOfTypeExcept`, so 🛑 halting the execution of next steps"
123+
} else {
124+
"Continuing the execution of next steps, as the step qualifies `haltOnFailureOfTypeExcept`"
135125
}
136126
}
127+
}
137128
}
138129
}
139130
}

src/main/kotlin/com/salesforce/revoman/output/Rundown.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.salesforce.revoman.output.report.StepReport
1515
data class Rundown(
1616
@JvmField val stepReports: List<StepReport> = emptyList(),
1717
@JvmField val mutableEnv: PostmanEnvironment<Any?>,
18-
private val stepsToIgnoreForFailurePick: Map<ExeType, PostTxnStepPick>?,
18+
private val haltOnFailureOfTypeExcept: Map<ExeType, PostTxnStepPick?>,
1919
) {
2020
@get:JvmName("immutableEnv") val immutableEnv: Map<String, Any?> by lazy { mutableEnv.toMap() }
2121

@@ -27,24 +27,16 @@ data class Rundown(
2727
@get:JvmName("firstUnIgnoredUnsuccessfulStepReport")
2828
val firstUnIgnoredUnsuccessfulStepReport: StepReport? by lazy {
2929
stepReports.firstOrNull { stepReport ->
30-
!stepReport.isSuccessful && !isStepIgnoredForFailure(stepReport)
30+
!stepReport.isSuccessful && !isStepIgnoredForFailure(stepReport, this)
3131
}
3232
}
3333

34-
private fun isStepIgnoredForFailure(stepReport: StepReport): Boolean =
35-
stepsToIgnoreForFailurePick
36-
?.asSequence()
37-
?.map { (exeType, postTxnPick) ->
38-
stepReport.exeTypeForFailure == exeType && postTxnPick.pick(stepReport, this)
39-
}
40-
?.any { it } ?: false
41-
4234
@get:JvmName("areAllStepsSuccessful")
4335
val areAllStepsSuccessful: Boolean by lazy { stepReports.all { it.isSuccessful } }
4436

4537
@get:JvmName("areAllStepsExceptIgnoredSuccessful")
4638
val areAllStepsExceptIgnoredSuccessful: Boolean by lazy {
47-
stepReports.all { it.isSuccessful || !isStepIgnoredForFailure(it) }
39+
stepReports.all { it.isSuccessful || !isStepIgnoredForFailure(it, this) }
4840
}
4941

5042
fun reportsForStepsInFolder(folderName: String): List<StepReport?> =
@@ -61,6 +53,17 @@ data class Rundown(
6153

6254
fun filterReportIncludingStepsWithName(stepNames: Set<String>): List<StepReport> =
6355
stepReports.filter { r -> stepNames.any { r.step.stepNameMatches(it) } }
56+
57+
companion object {
58+
fun isStepIgnoredForFailure(stepReport: StepReport, rundown: Rundown): Boolean =
59+
rundown.haltOnFailureOfTypeExcept
60+
.asSequence()
61+
.map { (exeType, postTxnPick) ->
62+
stepReport.exeTypeForFailure == exeType &&
63+
(postTxnPick?.pick(stepReport, rundown) ?: false)
64+
}
65+
.any { it }
66+
}
6467
}
6568

6669
fun <T> List<T>.endsWith(list: List<T>): Boolean =

0 commit comments

Comments
 (0)