-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_test.go
86 lines (75 loc) · 2.06 KB
/
check_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"os"
"strings"
"testing"
"time"
)
func TestCheck(t *testing.T) {
oogway := Dojo(
&oogway{
ChecksDir: "t/suiteB",
CheckInterval: 1 * time.Millisecond,
ChecksExtension: "oog",
})
// load our checks
oogway.loadChecks()
// lets pluck out a specific check
check, exists := oogway.checks["oogway.test"]
if !exists {
t.Fatalf("oogway.test is required for this test")
}
if check.Attempts != 0 {
t.Fatalf("Should be starting off on a clean slate. Attempts should be zero")
}
// go through 100 checks as fast as you can ...
for x := 0; x <= 100; x++ {
check.check()
}
// give everything a quick second to catch up(go routines ... )
<-time.After(time.Second)
// based on how I have the test setup, the check should be in an OK state now.
if check.Attempts != 0 {
t.Fatalf("Should be starting off on a clean slate. Attempts should be zero")
}
// Make sure the state is ok
if strings.ToLower(check.Status) != "ok" {
t.Fatalf("Expected state to be ok")
}
// ok, lets make sure a bunch of files exist ;)
outputExists := []string{
"/tmp/oogway.test.check.0",
"/tmp/oogway.test.check.1",
"/tmp/oogway.test.check.2",
"/tmp/oogway.test.check.3",
"/tmp/oogway.test.check.15",
"/tmp/oogway.test.warn.1",
"/tmp/oogway.test.warn.2",
"/tmp/oogway.test.warn.3",
"/tmp/oogway.test.warn.4",
"/tmp/oogway.test.fix.3",
"/tmp/oogway.test.fix.4",
"/tmp/oogway.test.fix.5",
"/tmp/oogway.test.critical.5",
}
for _, f := range outputExists {
if _, err := os.Stat(f); os.IsNotExist(err) {
// path/to/whatever does not exist
t.Fatalf("Expected " + string(f) + " to exist")
}
}
// ok, now lets verify that the path is looking ok
outputShouldNotExist := []string{
"/tmp/oogway.test.check.30",
"/tmp/oogway.test.warn.5",
"/tmp/oogway.test.warn.6",
"/tmp/oogway.test.fix.2",
"/tmp/oogway.test.critical.6",
}
for _, f := range outputShouldNotExist {
if _, err := os.Stat(f); !os.IsNotExist(err) {
// path/to/whatever does not exist
t.Fatalf("The file " + string(f) + " should not exist")
}
}
}