Add some test cases to cover main

These don't include any asserts, but they do check panics
This commit is contained in:
Ian Fijolek
2019-10-04 15:46:49 -07:00
parent 6aaeeb32d4
commit f99ee9891e
2 changed files with 130 additions and 4 deletions
+8 -4
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"time"
)
@@ -12,11 +13,14 @@ func checkMonitors(config *Config) {
// Should probably consider refactoring everything below here
if alertNotice != nil {
log.Printf("DEBUG: Recieved an alert notice: %v", alertNotice)
log.Printf("DEBUG: Recieved an alert notice from %s", alertNotice.MonitorName)
alertNames := monitor.GetAlertNames(alertNotice.IsUp)
if alertNames == nil {
// TODO: Should this be a panic? Should this be validated against? Probably
log.Printf("WARNING: Found alert, but no alert mechanisms exist: %v", alertNotice)
log.Printf(
"WARNING: Recieved alert, but no alert mechanisms exist. MonitorName=%s IsUp=%t",
alertNotice.MonitorName, alertNotice.IsUp,
)
}
for _, alertName := range alertNames {
if alert, ok := config.Alerts[alertName]; ok {
@@ -29,12 +33,12 @@ func checkMonitors(config *Config) {
output,
)
// TODO: Maybe return this error instead of panicking here
log.Fatalf(
panic(fmt.Errorf(
"ERROR: Unsuccessfully triggered alert '%s'. "+
"Crashing to avoid false negatives: %v",
alert.Name,
err,
)
))
}
} else {
// TODO: Maybe panic here. Also, probably validate up front