-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathpoint_test.go
122 lines (97 loc) · 2.31 KB
/
point_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
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func TestAddCounter(t *testing.T) {
p1 := &point{
Name: "my counter",
Type: counter,
Value: int64(10),
}
p2 := &point{
Name: "my counter",
Type: counter,
Value: int64(5),
}
err := p1.add(p2)
if err != nil {
t.Error(err)
}
if expect := int64(15); p1.Value != expect {
t.Errorf("expected '%d', got '%d'", expect, p1.Value)
}
p3 := &point{
Name: "my gauge",
Type: gauge,
Value: int64(10),
}
err = p1.add(p3)
if err != ErrIncompatiblePointType {
t.Errorf("incompatible point types should raise error")
}
if want, got := float64(15), p1.promValue(); want != got {
t.Errorf("want '%f', got '%f'", want, got)
}
if want, got := prometheus.ValueType(1), p1.promType(); want != got {
t.Errorf("want '%v', got '%v'", want, got)
}
wanted := `Desc{fqName: "rsyslog_my counter", help: "", constLabels: {}, variableLabels: []}`
if want, got := wanted, p1.promDescription().String(); want != got {
t.Errorf("want '%s', got '%s'", want, got)
}
}
func TestAddGauge(t *testing.T) {
p1 := &point{
Name: "my gauge",
Type: gauge,
Value: int64(10),
}
p2 := &point{
Name: "my gauge",
Type: gauge,
Value: int64(5),
}
err := p1.add(p2)
if err != nil {
t.Error(err)
}
if want, got := int64(5), p1.Value; want != got {
t.Errorf("want '%d', got '%d'", want, got)
}
p3 := &point{
Name: "my counter",
Type: counter,
Value: int64(10),
}
err = p1.add(p3)
if err != ErrIncompatiblePointType {
t.Errorf("incompatible point types should raise error")
}
if want, got := float64(5), p1.promValue(); want != got {
t.Errorf("want '%f', got '%f'", want, got)
}
if want, got := prometheus.ValueType(2), p1.promType(); want != got {
t.Errorf("want '%v', got '%v'", want, got)
}
wanted := `Desc{fqName: "rsyslog_my gauge", help: "", constLabels: {}, variableLabels: []}`
if want, got := wanted, p1.promDescription().String(); want != got {
t.Errorf("want '%s', got '%s'", want, got)
}
}
func TestAddNotHandled(t *testing.T) {
p1 := &point{
Name: "my gauge",
Type: gauge,
Value: int64(10),
}
p2 := &point{
Name: "bad",
Type: 99,
Value: int64(5),
}
err := p1.add(p2)
if err != ErrUnknownPointType {
t.Errorf("incompatible point types should raise error")
}
}