-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch_test.go
56 lines (46 loc) · 2.06 KB
/
watch_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 main
import "testing"
import "github.com/stretchr/testify/assert"
func TestNewWatch(t *testing.T) {
rawJSON := []byte(`{
"duration": 0,
"name": "completed",
"tags": [
"www.finishline.com",
"rmn_p1_variant_20180918"
],
"condition": {
"op": "<",
"value": 10250
},
"slackChannel": "#z_development"
}`)
watch := NewWatch("1", rawJSON, nil, "slack_webhook")
assert.Equal(t, "1", watch.ID)
assert.Equal(t, int64(0), watch.Duration)
assert.Equal(t, "<", watch.Condition.Op)
assert.Equal(t, int64(10250), watch.Condition.Value)
assert.Equal(t, "completed with tags[www.finishline.com,rmn_p1_variant_20180918] aggregating at 0s", watch.String())
assert.Equal(t, int64(-1), watch.NextCheck)
assert.Equal(t, true, watch.LastChecked > 1000)
}
func TestNewCondition(t *testing.T) {
condition := NewCondition(">", int64(10240))
assert.Equal(t, ">", condition.Op)
assert.Equal(t, int64(10240), condition.Value)
}
func TestConditionHasBreached(t *testing.T) {
assert.Equal(t, true, NewCondition(">", int64(10240)).HasBreached(int64(10241)))
assert.Equal(t, false, NewCondition(">", int64(10240)).HasBreached(int64(10240)))
assert.Equal(t, true, NewCondition("<", int64(10240)).HasBreached(int64(10239)))
assert.Equal(t, false, NewCondition("<", int64(10240)).HasBreached(int64(10241)))
assert.Equal(t, true, NewCondition("=", int64(10240)).HasBreached(int64(10240)))
assert.Equal(t, false, NewCondition("=", int64(10240)).HasBreached(int64(10241)))
assert.Equal(t, true, NewCondition("<=", int64(10240)).HasBreached(int64(10240)))
assert.Equal(t, true, NewCondition("<=", int64(10240)).HasBreached(int64(10240)))
assert.Equal(t, false, NewCondition("<=", int64(10240)).HasBreached(int64(10241)))
assert.Equal(t, true, NewCondition(">=", int64(10240)).HasBreached(int64(10240)))
assert.Equal(t, true, NewCondition(">=", int64(10240)).HasBreached(int64(10241)))
assert.Equal(t, false, NewCondition(">=", int64(10240)).HasBreached(int64(10239)))
assert.Equal(t, false, NewCondition("!", int64(10240)).HasBreached(int64(10241)))
}