-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilter_test.go
68 lines (55 loc) · 1.8 KB
/
filter_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
package filter
import "github.com/bmizerany/assert"
import "testing"
import "bytes"
func TestBooleanFilter(t *testing.T) {
in := bytes.NewBufferString(`
gauges.api-1.memory.percent|80|1421164536386
gauges.api-2.memory.percent|30|1421164536386
gauges.ingestion-2.memory.percent|50|1421164536386
gauges.api-3.memory.percent|50|1421164536386
gauges.cdn-1.memory.percent|50|1421164536386
gauges.cdn-2.memory.percent|50|1421164536386
gauges.ingestion-1.memory.percent|50|1421164536386`)
out := bytes.NewBuffer(nil)
conf := Config{
`^gauges\.api-*`: true,
`^gauges\.cdn-*`: true,
}
err := Filter(in, out, conf)
assert.Equal(t, nil, err)
exp := `gauges.api-1.memory.percent|80|1421164536386
gauges.api-2.memory.percent|30|1421164536386
gauges.api-3.memory.percent|50|1421164536386
gauges.cdn-1.memory.percent|50|1421164536386
gauges.cdn-2.memory.percent|50|1421164536386
`
assert.Equal(t, exp, string(out.Bytes()))
}
func TestStringMapping(t *testing.T) {
in := bytes.NewBufferString(`
gauges.api-1.memory.percent|80|1421164536386
gauges.api-2.memory.percent|30|1421164536386
gauges.ingestion-2.memory.percent|50|1421164536386
gauges.api-3.memory.percent|50|1421164536386
gauges.cdn-1.memory.percent|50|1421164536386
gauges.cdn-2.memory.percent|50|1421164536386
counts.app.#s|10|1421164536386
gauges.ingestion-1.memory.percent|50|1421164536386`)
out := bytes.NewBuffer(nil)
conf := Config{
`^counts\.app`: true,
`^gauges\.(api-\d+)`: "$1",
`^gauges\.cdn-(\d+)\.(.*)`: "content-$1-$2",
}
err := Filter(in, out, conf)
assert.Equal(t, nil, err)
exp := `api-1|80|1421164536386
api-2|30|1421164536386
api-3|50|1421164536386
content-1-memory.percent|50|1421164536386
content-2-memory.percent|50|1421164536386
counts.app.#s|10|1421164536386
`
assert.Equal(t, exp, string(out.Bytes()))
}