forked from zorkian/go-datadog-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
108 lines (85 loc) · 2.56 KB
/
helper_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
/*
* Datadog API for Go
*
* Please see the included LICENSE file for licensing information.
*
* Copyright 2017 by authors and contributors.
*/
package datadog_test
import (
"testing"
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/zorkian/go-datadog-api"
)
func TestHelperGetBoolSet(t *testing.T) {
// Assert that we were able to get the boolean from a pointer field
m := getTestMonitor()
if attr, ok := datadog.GetBool(m.Options.NotifyNoData); ok {
assert.Equal(t, true, attr)
}
}
func TestHelperGetBoolNotSet(t *testing.T) {
// Assert GetBool returned false for an unset value
m := getTestMonitor()
_, ok := datadog.GetBool(m.Options.NotifyAudit)
assert.Equal(t, false, ok)
}
func TestHelperStringSet(t *testing.T) {
// Assert that we were able to get the string from a pointer field
m := getTestMonitor()
if attr, ok := datadog.GetStringOk(m.Name); ok {
assert.Equal(t, "Test monitor", attr)
}
}
func TestHelperStringNotSet(t *testing.T) {
// Assert GetString returned false for an unset value
m := getTestMonitor()
_, ok := datadog.GetStringOk(m.Message)
assert.Equal(t, false, ok)
}
func TestHelperIntSet(t *testing.T) {
// Assert that we were able to get the integer from a pointer field
m := getTestMonitor()
if attr, ok := datadog.GetIntOk(m.Id); ok {
assert.Equal(t, 1, attr)
}
}
func TestHelperIntNotSet(t *testing.T) {
// Assert GetInt returned false for an unset value
m := getTestMonitor()
_, ok := datadog.GetIntOk(m.Options.RenotifyInterval)
assert.Equal(t, false, ok)
}
func TestHelperGetJsonNumberSet(t *testing.T) {
// Assert that we were able to get a JSON Number from a pointer field
m := getTestMonitor()
if attr, ok := datadog.GetJsonNumberOk(m.Options.Thresholds.Ok); ok {
assert.Equal(t, json.Number(2), attr)
}
}
func TestHelperGetJsonNumberNotSet(t *testing.T) {
// Assert GetJsonNumber returned false for an unset value
m := getTestMonitor()
_, ok := datadog.GetJsonNumberOk(m.Options.Thresholds.Warning)
assert.Equal(t, false, ok)
}
func getTestMonitor() *datadog.Monitor {
o := &datadog.Options{
NotifyNoData: datadog.Bool(true),
Locked: datadog.Bool(false),
NoDataTimeframe: 60,
Silenced: map[string]int{},
Thresholds: &datadog.ThresholdCount{
Ok: datadog.JsonNumber(json.Number(2)),
},
}
return &datadog.Monitor{
Query: datadog.String("avg(last_15m):avg:system.disk.in_use{*} by {host,device} > 0.8"),
Name: datadog.String("Test monitor"),
Id: datadog.Int(1),
Options: o,
Type: datadog.String("metric alert"),
Tags: make([]string, 0),
}
}