-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
reporter_test.go
56 lines (44 loc) · 1.35 KB
/
reporter_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
package datadog
import (
"github.com/rcrowley/go-metrics"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSplitNameAndTagsNoTags(t *testing.T) {
reporter := &Reporter{
Registry: metrics.DefaultRegistry,
}
var metricName = "test.metric_name"
name, tags := reporter.splitNameAndTags(metricName)
assert.NotNil(t, name, "name")
assert.Nil(t, tags, "tags")
assert.Equal(t, "test.metric_name", name)
}
func TestSplitNameAndTagsSingleTag(t *testing.T) {
reporter := &Reporter{
Registry: metrics.DefaultRegistry,
}
var metricName = "test.httpcall[method:GET]"
name, tags := reporter.splitNameAndTags(metricName)
assert.NotNil(t, name, "name")
assert.NotNil(t, tags, "tags")
assert.Equal(t, 1, len(tags))
assert.Equal(t, "test.httpcall", name)
assert.Equal(t, "method:GET", tags[0])
}
func TestSplitNameAndTagsMultipleTag(t *testing.T) {
globalTags := []string{"globaltag:true"}
reporter := &Reporter{
Registry: metrics.DefaultRegistry,
tags: globalTags,
}
var metricName = "test.httpcall[method:GET]"
name, tags := reporter.splitNameAndTags(metricName)
assert.NotNil(t, name, "name")
assert.NotNil(t, tags, "tags")
//expect two tags: the global tag and the metric level tag
assert.Equal(t, 2, len(tags))
assert.Equal(t, "test.httpcall", name)
assert.Equal(t, "method:GET", tags[0])
assert.Equal(t, "globaltag:true", tags[1])
}