forked from criteo/marathon_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontainers_test.go
72 lines (63 loc) · 1.54 KB
/
containers_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
package main
import "testing"
func Test_container_key(t *testing.T) {
cases := []struct {
name string
labels []string
expect string
}{
{
name: "foo",
labels: []string{},
expect: "foo{}",
}, {
name: "foo",
labels: []string{"value"},
expect: "foo{value}",
}, {
name: "foo",
labels: []string{"value", "color"},
expect: "foo{color,value}",
},
}
for _, c := range cases {
key := containerKey(c.name, c.labels)
if key != c.expect {
t.Errorf("expected container key %s, got %s", c.expect, key)
}
}
}
func Test_container_fetch_counter(t *testing.T) {
container := NewCounterContainer("marathon")
_, new := container.Fetch("foo", "")
if !new {
t.Fatal("expected a new counter")
}
if len(container.counters) != 1 {
t.Fatalf("expected a counter, got %d counters", len(container.counters))
}
_, new = container.Fetch("foo", "")
if new {
t.Fatal("expected an existing counter")
}
if len(container.counters) != 1 {
t.Fatalf("expected same counter as before, go %d counters", len(container.counters))
}
}
func Test_container_fetch_gauge(t *testing.T) {
container := NewGaugeContainer("marathon")
_, new := container.Fetch("foo", "")
if !new {
t.Fatal("expected a new gauge")
}
if len(container.gauges) != 1 {
t.Fatalf("expected a gauge, got %d gauges", len(container.gauges))
}
_, new = container.Fetch("foo", "")
if new {
t.Fatal("expected an existing gauge")
}
if len(container.gauges) != 1 {
t.Fatalf("expected same gauge as before, go %d gauges", len(container.gauges))
}
}