forked from atlassian/gostatsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_test.go
55 lines (50 loc) · 1.48 KB
/
metrics_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
package gostatsd
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestMetricReset(t *testing.T) {
// this is deliberately constructed without using named fields,
// so that if the fields change it will cause a compiler error.
m := &Metric{
"metric",
10,
1,
Tags{"tag"},
"something",
"somethingelse",
"source",
123,
COUNTER,
nil,
}
m.Reset()
// Tags needs to be an empty slice, not a nil slice, because half the reason
// behind having the MetricPool and Reset is to re-use the Tags slice. Therefore
// we don't nil it.
require.EqualValues(t, &Metric{Tags: Tags{}, Rate: 1}, m)
}
func TestMetricString(t *testing.T) {
types := []MetricType{COUNTER, TIMER, SET, GAUGE, 42}
names := []string{"counter", "timer", "set", "gauge", "unknown"}
for idx, name := range names {
require.Equal(t, name, types[idx].String())
}
}
func TestUpdateTags(t *testing.T) {
m := &Metric{}
m.FormatTagsKey()
require.EqualValues(t, "", m.TagsKey)
m.AddTagsSetSource(Tags{"foo"}, "source")
require.EqualValues(t, Tags{"foo"}, m.Tags)
require.EqualValues(t, "source", m.Source)
require.EqualValues(t, "", m.TagsKey)
m.FormatTagsKey()
require.EqualValues(t, "foo,s:source", m.TagsKey) // It's set
m.AddTagsSetSource(Tags{"foo2"}, "source2")
require.EqualValues(t, Tags{"foo", "foo2"}, m.Tags)
require.EqualValues(t, "source2", m.Source)
require.EqualValues(t, "", m.TagsKey) // It's cleared
m.FormatTagsKey()
require.EqualValues(t, "foo,foo2,s:source2", m.TagsKey)
}