Skip to content

Commit

Permalink
Updated tests.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Feb 6, 2024
1 parent 37884c4 commit 40d6a88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AlertTests {
assertEquals(templateArgs[Alert.START_TIME_FIELD], alert.startTime.toEpochMilli(), "Template args start time does not")
assertEquals(templateArgs[Alert.LAST_NOTIFICATION_TIME_FIELD], null, "Template args last notification time does not match")
assertEquals(templateArgs[Alert.SEVERITY_FIELD], alert.severity, "Template args severity does not match")
assertEquals(templateArgs[Alert.CLUSTERS_FIELD], alert.clusters?.joinToString(","), "Template args clusters does not match")
}

@Test
Expand All @@ -40,6 +41,7 @@ class AlertTests {
assertEquals(templateArgs[Alert.START_TIME_FIELD], alert.startTime.toEpochMilli(), "Template args start time does not")
assertEquals(templateArgs[Alert.LAST_NOTIFICATION_TIME_FIELD], null, "Template args last notification time does not match")
assertEquals(templateArgs[Alert.SEVERITY_FIELD], alert.severity, "Template args severity does not match")
assertEquals(templateArgs[Alert.CLUSTERS_FIELD], alert.clusters?.joinToString(","), "Template args clusters does not match")
assertEquals(
templateArgs[Alert.BUCKET_KEYS],
alert.aggregationResultBucket?.bucketKeys?.joinToString(","),
Expand Down
18 changes: 7 additions & 11 deletions src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ fun randomDocumentLevelTrigger(
name = name,
severity = severity,
condition = condition,
actions = if (actions.isEmpty() && destinationId.isNotBlank()) {
actions = if (actions.isEmpty() && destinationId.isNotBlank())
(0..RandomNumbers.randomIntBetween(Random(), 0, 10)).map { randomAction(destinationId = destinationId) }
} else actions
else actions
)
}

Expand Down Expand Up @@ -527,12 +527,11 @@ 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
monitor, trigger, Instant.now().truncatedTo(ChronoUnit.MILLIS), null,
actionExecutionResults = actionExecutionResults, clusters = clusters
)
}

Expand Down Expand Up @@ -562,10 +561,7 @@ fun randomAlertWithAggregationResultBucket(monitor: Monitor = randomBucketLevelM
val trigger = randomBucketLevelTrigger()
val actionExecutionResults = mutableListOf(randomActionExecutionResult(), randomActionExecutionResult())
return Alert(
monitor,
trigger,
Instant.now().truncatedTo(ChronoUnit.MILLIS),
null,
monitor, trigger, Instant.now().truncatedTo(ChronoUnit.MILLIS), null,
actionExecutionResults = actionExecutionResults,
aggregationResultBucket = AggregationResultBucket(
"parent_bucket_path_1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ class XContentTests {
errorMessage = "some error",
lastNotificationTime = Instant.now(),
workflowId = "",
executionId = ""
executionId = "",
clusters = listOf()
)
assertEquals("Round tripping alert doesn't work", alert.triggerName, "NoOp trigger")
}
Expand All @@ -462,7 +463,8 @@ class XContentTests {
"\"state\":\"ACTIVE\",\"error_message\":null,\"alert_history\":[],\"severity\":\"1\",\"action_execution_results\"" +
":[{\"action_id\":\"ghe1-XQBySl0wQKDBkOG\",\"last_execution_time\":1601917224583,\"throttled_count\":-1478015168}," +
"{\"action_id\":\"gxe1-XQBySl0wQKDBkOH\",\"last_execution_time\":1601917224583,\"throttled_count\":-768533744}]," +
"\"start_time\":1601917224599,\"last_notification_time\":null,\"end_time\":null,\"acknowledged_time\":null}"
"\"start_time\":1601917224599,\"last_notification_time\":null,\"end_time\":null,\"acknowledged_time\":null," +
"\"clusters\":[\"cluster-1\",\"cluster-2\"]}"
val parsedAlert = Alert.parse(parser(alertStr))
OpenSearchTestCase.assertNull(parsedAlert.monitorUser)
}
Expand All @@ -475,7 +477,8 @@ class XContentTests {
"\"state\":\"ACTIVE\",\"error_message\":null,\"alert_history\":[],\"severity\":\"1\",\"action_execution_results\"" +
":[{\"action_id\":\"ghe1-XQBySl0wQKDBkOG\",\"last_execution_time\":1601917224583,\"throttled_count\":-1478015168}," +
"{\"action_id\":\"gxe1-XQBySl0wQKDBkOH\",\"last_execution_time\":1601917224583,\"throttled_count\":-768533744}]," +
"\"start_time\":1601917224599,\"last_notification_time\":null,\"end_time\":null,\"acknowledged_time\":null}"
"\"start_time\":1601917224599,\"last_notification_time\":null,\"end_time\":null,\"acknowledged_time\":null," +
"\"clusters\":[\"cluster-1\",\"cluster-2\"]}"
val parsedAlert = Alert.parse(parser(alertStr))
OpenSearchTestCase.assertNull(parsedAlert.monitorUser)
}
Expand Down

0 comments on commit 40d6a88

Please sign in to comment.