mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-07 14:47:11 +02:00
[REFACTOR] Labels: Extract test case data from TestLabels_String
So we can use them in other tests. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
d902abc50d
commit
507227781b
@ -26,37 +26,31 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLabels_String(t *testing.T) {
|
var (
|
||||||
s254 := strings.Repeat("x", 254) // Edge cases for stringlabels encoding.
|
s254 = strings.Repeat("x", 254) // Edge cases for stringlabels encoding.
|
||||||
s255 := strings.Repeat("x", 255)
|
s255 = strings.Repeat("x", 255)
|
||||||
cases := []struct {
|
)
|
||||||
labels Labels
|
|
||||||
expected string
|
var testCaseLabels = []Labels{
|
||||||
}{
|
FromStrings("t1", "t1", "t2", "t2"),
|
||||||
{
|
{},
|
||||||
labels: FromStrings("t1", "t1", "t2", "t2"),
|
FromStrings("service.name", "t1", "whatever\\whatever", "t2"),
|
||||||
expected: "{t1=\"t1\", t2=\"t2\"}",
|
FromStrings("aaa", "111", "xx", s254),
|
||||||
},
|
FromStrings("aaa", "111", "xx", s255),
|
||||||
{
|
|
||||||
labels: Labels{},
|
|
||||||
expected: "{}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labels: FromStrings("service.name", "t1", "whatever\\whatever", "t2"),
|
|
||||||
expected: `{"service.name"="t1", "whatever\\whatever"="t2"}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labels: FromStrings("aaa", "111", "xx", s254),
|
|
||||||
expected: `{aaa="111", xx="` + s254 + `"}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labels: FromStrings("aaa", "111", "xx", s255),
|
|
||||||
expected: `{aaa="111", xx="` + s255 + `"}`,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
|
||||||
str := c.labels.String()
|
func TestLabels_String(t *testing.T) {
|
||||||
require.Equal(t, c.expected, str)
|
expected := []string{ // Values must line up with testCaseLabels.
|
||||||
|
"{t1=\"t1\", t2=\"t2\"}",
|
||||||
|
"{}",
|
||||||
|
`{"service.name"="t1", "whatever\\whatever"="t2"}`,
|
||||||
|
`{aaa="111", xx="` + s254 + `"}`,
|
||||||
|
`{aaa="111", xx="` + s255 + `"}`,
|
||||||
|
}
|
||||||
|
require.Equal(t, len(testCaseLabels), len(expected))
|
||||||
|
for i, c := range expected {
|
||||||
|
str := testCaseLabels[i].String()
|
||||||
|
require.Equal(t, c, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user