forked from soundcloud/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 9
/
inputs_test.go
49 lines (38 loc) · 1.19 KB
/
inputs_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
package main
import "testing"
var (
inputLog = []byte(`{"name":"test_input", "origin":"imuxsock", "submitted":1000}`)
)
func TestgetInput(t *testing.T) {
logType := getStatType(inputLog)
if logType != rsyslogInput {
t.Errorf("detected pstat type should be %d but is %d", rsyslogInput, logType)
}
pstat, err := newInputFromJSON([]byte(inputLog))
if err != nil {
t.Fatalf("expected parsing input stat not to fail, got: %v", err)
}
if want, got := "test_input", pstat.Name; want != got {
t.Errorf("want '%s', got '%s'", want, got)
}
if want, got := int64(1000), pstat.Submitted; want != got {
t.Errorf("want '%d', got '%d'", want, got)
}
}
func TestInputtoPoints(t *testing.T) {
pstat, err := newInputFromJSON([]byte(inputLog))
if err != nil {
t.Fatalf("expected parsing input stat not to fail, got: %v", err)
}
points := pstat.toPoints()
point := points[0]
if want, got := "input_submitted", point.Name; want != got {
t.Errorf("want '%s', got '%s'", want, got)
}
if want, got := int64(1000), point.Value; want != got {
t.Errorf("want '%d', got '%d'", want, got)
}
if want, got := "test_input", point.LabelValue; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
}