-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatsd_test.go
More file actions
76 lines (73 loc) · 1.57 KB
/
statsd_test.go
File metadata and controls
76 lines (73 loc) · 1.57 KB
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
package main
import (
"reflect"
"testing"
)
func TestParseStat(t *testing.T) {
var cases = []struct {
description string
input string
shouldError bool
expected *Stat
}{
{
description: "Boring stat",
input: "bar.foo.baz:5|c",
shouldError: false,
expected: &Stat{
Name: "bar.foo.baz",
Type: "c",
Value: "5",
},
},
{
description: "Stat with sample rate",
input: "bar.foo.baz:5|c|@0.5",
shouldError: false,
expected: &Stat{
Name: "bar.foo.baz",
Type: "c",
Value: "5",
SampleRate: "@0.5",
},
},
{
description: "Stat with tags",
input: "bar.foo.baz:5|c#foo:bar,baz:bang",
shouldError: false,
expected: &Stat{
Name: "bar.foo.baz",
Type: "c",
Value: "5",
Tags: []string{"baz:bang", "foo:bar"},
},
},
{
description: "Stat with sample rate and tags",
input: "bar.foo.baz:5|c|@0.5#foo:bar,baz:bang",
shouldError: false,
expected: &Stat{
Name: "bar.foo.baz",
Type: "c",
Value: "5",
SampleRate: "@0.5",
Tags: []string{"baz:bang", "foo:bar"},
},
},
{
description: "Not a stat at all",
input: "Hello there!",
shouldError: true,
expected: nil,
},
}
for _, tc := range cases {
t.Logf("Running test case '%s' ", tc.description)
res, err := parseStat(tc.input)
if err != nil && !tc.shouldError {
t.Errorf("Test failed with error %s", err)
} else if !reflect.DeepEqual(tc.expected, res) {
t.Errorf("Expected %v but got %v", tc.expected, res)
}
}
}