-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathserializer_test.go
113 lines (105 loc) · 1.99 KB
/
serializer_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
package datadog
import (
"testing"
"time"
"github.com/segmentio/stats/v5"
)
var testMeasures = []struct {
m stats.Measure
s string
dp []string
}{
{
m: stats.Measure{
Name: "request",
Fields: []stats.Field{
stats.MakeField("count", 5, stats.Counter),
},
},
s: `request.count:5|c
`,
dp: []string{},
},
{
m: stats.Measure{
Name: "request",
Fields: []stats.Field{
stats.MakeField("count", 5, stats.Counter),
stats.MakeField("rtt", 100*time.Millisecond, stats.Histogram),
},
Tags: []stats.Tag{
stats.T("answer", "42"),
stats.T("hello", "world"),
},
},
s: `request.count:5|c|#answer:42,hello:world
request.rtt:0.1|h|#answer:42,hello:world
`,
dp: []string{},
},
{
m: stats.Measure{
Name: "request",
Fields: []stats.Field{
stats.MakeField("dist_rtt", 100*time.Millisecond, stats.Histogram),
},
Tags: []stats.Tag{
stats.T("answer", "42"),
stats.T("hello", "world"),
},
},
s: `request.dist_rtt:0.1|d|#answer:42,hello:world
`,
dp: []string{"dist_"},
},
}
func TestAppendMeasure(t *testing.T) {
client := NewClient(DefaultAddress)
for _, test := range testMeasures {
t.Run(test.s, func(t *testing.T) {
client.distPrefixes = test.dp
if s := string(client.AppendMeasure(nil, test.m)); s != test.s {
t.Error("bad metric representation:")
t.Log("expected:", test.s)
t.Log("found: ", s)
}
})
}
}
var (
testDistNames = []struct {
n string
d bool
}{
{
n: "name",
d: false,
},
{
n: "",
d: false,
},
{
n: "dist_name",
d: true,
},
{
n: "distname",
d: false,
},
}
distPrefixes = []string{"dist_"}
)
func TestSendDist(t *testing.T) {
client := NewClientWith(ClientConfig{DistributionPrefixes: distPrefixes})
for _, test := range testDistNames {
t.Run(test.n, func(t *testing.T) {
a := client.sendDist(test.n)
if a != test.d {
t.Error("distribution name detection incorrect:")
t.Log("expected:", test.d)
t.Log("found: ", a)
}
})
}
}