-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemplar_test.go
More file actions
38 lines (32 loc) · 990 Bytes
/
exemplar_test.go
File metadata and controls
38 lines (32 loc) · 990 Bytes
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
package openmetrics_test
import (
"testing"
. "github.com/bsm/openmetrics"
)
func TestExemplar_Validate(t *testing.T) {
t.Run("valid", func(t *testing.T) {
examples := []Exemplar{
{Value: 1.2, Labels: LabelSet{{"one", "val"}, {"two", "val"}}},
}
for i, x := range examples {
if err := x.Validate(); err != nil {
t.Errorf("[%d] expected no error, got %v", i, err)
}
}
})
t.Run("invalid name", func(t *testing.T) {
examples := []Exemplar{
{Value: 1.2, Labels: LabelSet{{"bad-key", "val"}, {"two", "val"}}},
{Value: 1.2, Labels: LabelSet{{"two", "val"}, {"one", "val"}, {"two", "val"}}}, // duplicate
{Value: 1.2, Labels: LabelSet{
{"one", "123456789.123456789.123456789.123456789.123456789.123456789.1"},
{"two", "123456789.123456789.123456789.123456789.123456789.123456789.12"}, // too long
}},
}
for i, x := range examples {
if err := x.Validate(); err == nil {
t.Errorf("[%d] expected error, got %v", i, err)
}
}
})
}