-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathMonitorTests.kt
46 lines (39 loc) · 1.43 KB
/
MonitorTests.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.opensearch.commons.alerting
import org.junit.jupiter.api.Test
import org.opensearch.commons.alerting.model.Trigger
import org.opensearch.test.OpenSearchTestCase
import java.lang.IllegalArgumentException
import java.time.Instant
internal class MonitorTests {
@Test
fun `test enabled time`() {
val monitor = randomQueryLevelMonitor()
val enabledMonitor = monitor.copy(enabled = true, enabledTime = Instant.now())
try {
enabledMonitor.copy(enabled = false)
OpenSearchTestCase.fail("Disabling monitor with enabled time set should fail.")
} catch (e: IllegalArgumentException) {
}
val disabledMonitor = monitor.copy(enabled = false, enabledTime = null)
try {
disabledMonitor.copy(enabled = true)
OpenSearchTestCase.fail("Enabling monitor without enabled time should fail")
} catch (e: IllegalArgumentException) {
}
}
@Test
fun `test max triggers`() {
val monitor = randomQueryLevelMonitor()
val tooManyTriggers = mutableListOf<Trigger>()
var i = 0
while (i <= 10) {
tooManyTriggers.add(randomQueryLevelTrigger())
++i
}
try {
monitor.copy(triggers = tooManyTriggers)
OpenSearchTestCase.fail("Monitor with too many triggers should be rejected.")
} catch (e: IllegalArgumentException) {
}
}
}