-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_test.go
56 lines (47 loc) · 1.51 KB
/
status_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
package servicestatus
import (
"encoding/json"
"os"
"testing"
)
func TestServiceStatus(t *testing.T) {
ss := NewServiceStatus("MyApp", "0.2.1")
ss.AddCheck("passing_check", "passing check description", func() bool { return true })
ss.AddCheck("failing_check", "failing check description", func() bool { return false })
statusJSON := ss.Status()
var s status
err := json.Unmarshal([]byte(statusJSON), &s)
if err != nil {
t.Error(err)
}
hostname, err := os.Hostname()
if err != nil {
t.Error(err)
}
tests := []struct {
name string
actual interface{}
expected interface{}
}{
{"name", s.Name, "MyApp"},
{"version", s.Version, "0.2.1"},
{"hostname", s.Hostname, hostname},
{"check size", len(s.Checks), 2},
{"passing check name", s.Checks[0].Name, "passing_check"},
{"failing check name", s.Checks[1].Name, "failing_check"},
{"passing check description", s.Checks[0].Description, "passing check description"},
{"failing check description", s.Checks[1].Description, "failing check description"},
{"check size", len(s.Errors), 1},
{"failing check name", s.Errors[0].Name, "failing_check"},
{"failing check description", s.Errors[0].Description, "failing check description"},
{"status", s.Status, "Offline"},
/*{"timestamp", s.Timestamp, "actual"},
{"uptime", s.Uptime, "actual"},
{"diskUsage", s.DiskUsage, "actual"},*/
}
for _, test := range tests {
if test.actual != test.expected {
t.Errorf("Expected %v to be %q but was %q.\n", test.name, test.expected, test.actual)
}
}
}