-
Notifications
You must be signed in to change notification settings - Fork 0
/
countervec1_test.go
70 lines (61 loc) · 1.22 KB
/
countervec1_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
package promvec
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func TestCounterVec1Empty(t *testing.T) {
var (
desc = make(chan *prometheus.Desc, 10)
coll = make(chan prometheus.Metric, 10)
)
v := NewCounterVec1(
prometheus.CounterOpts{
Name: "test",
Help: "test",
ConstLabels: nil,
},
"",
[]string{},
)
v.Describe(desc)
d, ok := <-desc
if !ok || d == nil || len(d.String()) == 0 {
t.Errorf("no description")
}
v.Collect(coll)
if have, want := len(coll), 0; have != want {
t.Errorf("have %v, want %v", have, want)
}
}
func TestCounterVec1(t *testing.T) {
var (
desc = make(chan *prometheus.Desc, 10)
coll = make(chan prometheus.Metric, 10)
)
v := NewCounterVec1(
prometheus.CounterOpts{
Name: "test",
Help: "test",
ConstLabels: nil,
},
"first",
[]string{
"a",
"aa",
},
)
v.Describe(desc)
d, ok := <-desc
if !ok || d == nil || len(d.String()) == 0 {
t.Errorf("no description")
}
v.Collect(coll)
if have, want := len(coll), 2; have != want {
t.Errorf("have %v, want %v", have, want)
}
c := v.WithLabelValues("aa")
d = c.Desc()
if d == nil || len(d.String()) == 0 {
t.Errorf("no counter description")
}
}