-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrowkey_test.go
101 lines (95 loc) · 2.06 KB
/
rowkey_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
package promtable_test
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/uschen/promtable"
"github.com/uschen/promtable/prompb"
)
func TestLabelsToRowKeyComponents(t *testing.T) {
tests := []struct {
input []prompb.Label
expName string
expLabelsString string
expErr error
}{
{
input: []prompb.Label{
{Name: promtable.MetricNameLabel, Value: "ma"},
{Name: "l1", Value: "v1"},
{Name: "l2", Value: "v2"},
},
expName: "ma",
expLabelsString: "l1,l2,v1,v2",
},
{
input: []prompb.Label{
{Name: "l1", Value: "v1"},
{Name: "l2", Value: "v2"},
},
expErr: errors.New(""),
},
{
input: []prompb.Label{
{Name: promtable.MetricNameLabel, Value: "ma"},
{Name: "l1", Value: "v1"},
{Name: "l2", Value: "v2,3"},
},
expName: "ma",
expLabelsString: "l1,l2,v1,v2%2c3",
},
{
input: []prompb.Label{
{Name: promtable.MetricNameLabel, Value: "ma"},
{Name: "l1", Value: ""},
{Name: "l2", Value: "v2"},
},
expName: "ma",
expLabelsString: "l1,l2,,v2",
},
}
for _, test := range tests {
name, labelsString, err := promtable.LabelsToRowKeyComponents(test.input)
if test.expErr == nil {
assert.Nil(t, err)
} else {
assert.NotNil(t, err)
}
assert.Equal(t, test.expName, name)
assert.Equal(t, test.expLabelsString, labelsString)
}
}
func TestLabelsFromString(t *testing.T) {
tests := []struct {
input string
expLabels []prompb.Label
expErr error
}{
{
input: "l1,l2,l3,l4,l5,,v2,v3,v4,v5%2c6",
expLabels: []prompb.Label{
{Name: "l1", Value: ""},
{Name: "l2", Value: "v2"},
{Name: "l3", Value: "v3"},
{Name: "l4", Value: "v4"},
{Name: "l5", Value: "v5,6"},
},
},
{
input: "",
},
{
input: "l1,l2,v1",
expErr: errors.New(""),
},
}
for _, test := range tests {
labels, err := promtable.LabelsFromString(test.input)
if test.expErr == nil {
assert.Nil(t, err)
} else {
assert.NotNil(t, err)
}
assert.EqualValues(t, test.expLabels, labels)
}
}