Add duration parsing tests
This commit is contained in:
parent
bdf7355fa7
commit
04395fa693
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadConfig(t *testing.T) {
|
func TestLoadConfig(t *testing.T) {
|
||||||
@ -35,10 +36,36 @@ func TestLoadConfig(t *testing.T) {
|
|||||||
|
|
||||||
// Set PyCompat to default value
|
// Set PyCompat to default value
|
||||||
PyCompat = false
|
PyCompat = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIntervalParsing(t *testing.T) {
|
||||||
|
log.Printf("Testing case TestIntervalParsing")
|
||||||
|
|
||||||
|
config, err := LoadConfig("./test/valid-config.yml")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed loading config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
oneSecond := time.Second
|
||||||
|
tenSeconds := 10 * time.Second
|
||||||
|
oneMinute := time.Minute
|
||||||
|
|
||||||
|
// validate top level interval seconds represented as an int
|
||||||
|
if config.CheckInterval != oneSecond {
|
||||||
|
t.Errorf("Incorrectly parsed int seconds. expected=%v actual=%v", oneSecond, config.CheckInterval)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Monitors[0].CheckInterval != tenSeconds {
|
||||||
|
t.Errorf("Incorrectly parsed seconds duration. expected=%v actual=%v", oneSecond, config.CheckInterval)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Monitors[1].CheckInterval != oneMinute {
|
||||||
|
t.Errorf("Incorrectly parsed seconds duration. expected=%v actual=%v", oneSecond, config.CheckInterval)
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("-----")
|
log.Println("-----")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TestMultiLineConfig is a more complicated test stepping through the parsing
|
// TestMultiLineConfig is a more complicated test stepping through the parsing
|
||||||
// and execution of mutli-line strings presented in YAML
|
// and execution of mutli-line strings presented in YAML
|
||||||
|
@ -45,9 +45,9 @@ func TestMonitorShouldCheck(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
}{
|
}{
|
||||||
{Monitor{}, true, "Empty"},
|
{Monitor{}, true, "Empty"},
|
||||||
{Monitor{lastCheck: timeNow, CheckInterval: 15}, false, "Just checked"},
|
{Monitor{lastCheck: timeNow, CheckInterval: time.Second * 15}, false, "Just checked"},
|
||||||
{Monitor{lastCheck: timeTenSecAgo, CheckInterval: 15}, false, "-10s"},
|
{Monitor{lastCheck: timeTenSecAgo, CheckInterval: time.Second * 15}, false, "-10s"},
|
||||||
{Monitor{lastCheck: timeTwentySecAgo, CheckInterval: 15}, true, "-20s"},
|
{Monitor{lastCheck: timeTwentySecAgo, CheckInterval: time.Second * 15}, true, "-20s"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
@ -3,21 +3,23 @@ check_interval: 1
|
|||||||
|
|
||||||
monitors:
|
monitors:
|
||||||
- name: Command
|
- name: Command
|
||||||
command: ['echo', '$PATH']
|
command: ["echo", "$PATH"]
|
||||||
alert_down: ['log_command', 'log_shell']
|
alert_down: ["log_command", "log_shell"]
|
||||||
alert_every: 0
|
alert_every: 0
|
||||||
|
check_interval: 10s
|
||||||
- name: Shell
|
- name: Shell
|
||||||
command: >
|
command: >
|
||||||
echo 'Some string with stuff';
|
echo 'Some string with stuff';
|
||||||
echo 'another line';
|
echo 'another line';
|
||||||
echo $PATH;
|
echo $PATH;
|
||||||
exit 1
|
exit 1
|
||||||
alert_down: ['log_command', 'log_shell']
|
alert_down: ["log_command", "log_shell"]
|
||||||
alert_after: 5
|
alert_after: 5
|
||||||
alert_every: 0
|
alert_every: 0
|
||||||
|
check_interval: 1m
|
||||||
|
|
||||||
alerts:
|
alerts:
|
||||||
log_command:
|
log_command:
|
||||||
command: ['echo', 'regular', '"command!!!"', "{{.MonitorName}}"]
|
command: ["echo", "regular", '"command!!!"', "{{.MonitorName}}"]
|
||||||
log_shell:
|
log_shell:
|
||||||
command: echo "Failure on {{.MonitorName}} User is $USER"
|
command: echo "Failure on {{.MonitorName}} User is $USER"
|
||||||
|
Loading…
Reference in New Issue
Block a user