forked from ksred/go-monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
108 lines (97 loc) · 2.26 KB
/
main_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"bytes"
"io/ioutil"
"testing"
)
func TestParseConf(t *testing.T) {
conf := ymlConf{}
// Construct yaml data
data := `
processes:
config:
`
err := parseConf([]byte(data), &conf)
if err == nil {
t.Errorf("Looking for %v, got %v", "We need to monitor at least one process", nil)
}
data = `
processes: [ "test" ]
config:
`
err = parseConf([]byte(data), &conf)
if err == nil {
t.Errorf("Looking for %v, got %v", "Not all config variables present", nil)
}
data = `
processes: [ "test" ]
config:
messagebirdtoken: "test"
messagebirdsender: "test"
recipients: "test"
defaultttl: 1
servernicename: "test"
`
err = parseConf([]byte(data), &conf)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
}
func TestParseConfFromFile(t *testing.T) {
conf := ymlConf{}
data, err := ioutil.ReadFile("go-monitor.yml")
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
err = parseConf(data, &conf)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
}
func TestGetServerInfo(t *testing.T) {
conf := ymlConf{}
data, err := ioutil.ReadFile("go-monitor.yml")
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
err = parseConf(data, &conf)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
_, err = getServerInfo(&conf)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
}
func TestCheckProc(t *testing.T) {
// @TODO Not sure how to test this without involving setting up a channel
}
func TestLineCount(t *testing.T) {
line := bytes.NewBufferString("test one line\n")
lines, err := lineCounter(line)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
if lines != 1 {
t.Errorf("Looking for %v, got %v", 1, lines)
}
line = bytes.NewBufferString("test one line\ntest two lines\n")
lines, err = lineCounter(line)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
if lines != 2 {
t.Errorf("Looking for %v, got %v", 2, lines)
}
line = bytes.NewBufferString("test one line\ntest two lines\nthree\nfour\nfive\n")
lines, err = lineCounter(line)
if err != nil {
t.Errorf("Looking for %v, got %v", nil, err)
}
if lines != 5 {
t.Errorf("Looking for %v, got %v", 5, lines)
}
}
func TestNotifyProcError(t *testing.T) {
// @TODO
}