-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathactions_test.go
110 lines (84 loc) · 2.87 KB
/
actions_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
109
110
package main
import "testing"
var (
actionLog = []byte(`{"name":"test_action","processed":100000,"failed":2,"suspended":1,"suspended.duration":1000,"resumed":1}`)
)
func TestNewActionFromJSON(t *testing.T) {
logType := getStatType(actionLog)
if logType != rsyslogAction {
t.Errorf("detected pstat type should be %d but is %d", rsyslogAction, logType)
}
pstat := newActionFromJSON([]byte(actionLog))
if want, got := "test_action", pstat.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(100000), pstat.Processed; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(2), pstat.Failed; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(1), pstat.Suspended; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(1000), pstat.SuspendedDuration; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(1), pstat.Resumed; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
}
func TestActionToPoints(t *testing.T) {
pstat := newActionFromJSON([]byte(actionLog))
points := pstat.toPoints()
point := points[0]
if want, got := "test_action_processed", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(100000), point.Value; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := counter, point.Type; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
point = points[1]
if want, got := "test_action_failed", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(2), point.Value; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := counter, point.Type; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
point = points[2]
if want, got := "test_action_suspended", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(1), point.Value; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := counter, point.Type; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
point = points[3]
if want, got := "test_action_suspended_duration", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(1000), point.Value; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := counter, point.Type; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
point = points[4]
if want, got := "test_action_resumed", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(1), point.Value; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := counter, point.Type; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
}