Skip to content

Commit

Permalink
Updated Alert test helpers to include the new 'clusters' field in the…
Browse files Browse the repository at this point in the history
… existing tests.

Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Feb 8, 2024
1 parent cfaecac commit 5090590
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,13 @@ fun assertUserNull(monitor: Monitor) {
fun randomAlert(monitor: Monitor = randomQueryLevelMonitor()): Alert {
val trigger = randomQueryLevelTrigger()
val actionExecutionResults = mutableListOf(randomActionExecutionResult(), randomActionExecutionResult())
val clusterCount = (-1..5).random()
val clusters = if (clusterCount == -1) null else (0..clusterCount).map { "index-$it" }
return Alert(
monitor,
trigger,
Instant.now().truncatedTo(ChronoUnit.MILLIS),
null,
actionExecutionResults = actionExecutionResults,
clusters = clusters
clusters = randomAlertClustersList()
)
}

Expand All @@ -555,7 +553,8 @@ fun randomChainedAlert(
executionId = UUID.randomUUID().toString(),
chainedAlertTrigger = trigger,
workflow = workflow,
associatedAlertIds = listOf("a1")
associatedAlertIds = listOf("a1"),
clusters = randomAlertClustersList()
)
}

Expand All @@ -578,7 +577,8 @@ fun randomAlertWithAggregationResultBucket(monitor: Monitor = randomBucketLevelM
"parent_bucket_path_1",
listOf("bucket_key_1"),
mapOf("k1" to "val1", "k2" to "val2")
)
),
clusters = randomAlertClustersList()
)
}

Expand All @@ -601,3 +601,15 @@ fun randomFinding(
timestamp = timestamp
)
}

/**
* In the [Alert] data model, [Alert.clusters] can be null, or a List<String>.
* @return This function will randomly return null, an empty list, or a list of 1-5 unique strings.
*/
fun randomAlertClustersList(): List<String>? {
return when (val clusterCount = (-1..5).random()) {
-1 -> null
0 -> emptyList()
else -> (0 until clusterCount).map { "cluster-$it" }
}
}

0 comments on commit 5090590

Please sign in to comment.