-
Notifications
You must be signed in to change notification settings - Fork 66
/
validator_test.go
61 lines (56 loc) · 1011 Bytes
/
validator_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
package metrics
import (
"testing"
)
func TestValidateMetricSuccess(t *testing.T) {
f := func(s string) {
t.Helper()
if err := validateMetric(s); err != nil {
t.Fatalf("cannot validate %q: %s", s, err)
}
}
f("a")
f("_9:8")
f("a{}")
f(`a{foo="bar"}`)
f(`foo{bar="baz", x="y\"z"}`)
f(`foo{bar="b}az"}`)
f(`:foo:bar{bar="a",baz="b"}`)
f(`some.foo{bar="baz"}`)
}
func TestValidateMetricError(t *testing.T) {
f := func(s string) {
t.Helper()
if err := validateMetric(s); err == nil {
t.Fatalf("expecting non-nil error when validating %q", s)
}
}
f("")
f("{}")
// superflouos space
f("a ")
f(" a")
f(" a ")
f("a {}")
f("a{} ")
f("a{ }")
f(`a{foo ="bar"}`)
f(`a{ foo="bar"}`)
f(`a{foo= "bar"}`)
f(`a{foo="bar" }`)
f(`a{foo="bar" ,baz="a"}`)
// invalid tags
f("a{foo}")
f("a{=}")
f(`a{=""}`)
f(`a{`)
f(`a}`)
f(`a{foo=}`)
f(`a{foo="`)
f(`a{foo="}`)
f(`a{foo="bar",}`)
f(`a{foo="bar", x`)
f(`a{foo="bar", x=`)
f(`a{foo="bar", x="`)
f(`a{foo="bar", x="}`)
}