-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_json_test.go
70 lines (59 loc) · 1.54 KB
/
check_json_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
package poller
import (
"bytes"
"encoding/json"
"fmt"
//"github.com/davecgh/go-spew/spew"
"testing"
)
var testJsonHttpCheck = `
{
"type": "http",
"key": "connect_sensiolabs_com_api",
"interval": "1m0s",
"alert": true,
"alertDelay": "1h0m0s",
"notifyFix": true,
"config": {
"headers": {
"Accept": "application/vnd.com.sensiolabs.connect+xml"
},
"url": "https://connect.sensiolabs.com/api/"
}
}`
func TestNewCheckFromJSON(t *testing.T) {
check, err := NewCheckFromJSON([]byte(testJsonHttpCheck))
if err != nil {
t.Error(err)
}
headers := check.Config.GetMapStringString("headers")
if headers["Accept"] != "application/vnd.com.sensiolabs.connect+xml" {
t.Error("Accept header is incorrect.")
}
if check.Interval.Seconds() != 60 {
t.Errorf("Interval should be equal to 60s.")
}
if check.Alert != true {
t.Errorf("Alert should be true.")
}
if check.AlertDelay.Seconds() != 3600 {
t.Errorf("Alert delay is wrong.")
}
if check.Config.GetString("url") != "https://connect.sensiolabs.com/api/" {
t.Errorf("delay is wrong.")
}
if check.NotifyFix != true {
t.Errorf("NotifyFix is wrong")
}
}
func TestCheckJSON(t *testing.T) {
buffer := new(bytes.Buffer)
check, _ := NewCheckFromJSON([]byte(testJsonHttpCheck))
marshaled, _ := check.JSON()
json.Compact(buffer, []byte(testJsonHttpCheck))
if string(marshaled) != buffer.String() {
fmt.Println(buffer.String())
fmt.Println(string(marshaled))
t.Errorf("JSON() do not output correct representation of Check")
}
}