mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promrelabel: add tests for labelsToString() function
This commit is contained in:
parent
269e35d676
commit
e7d353ee6a
2 changed files with 48 additions and 1 deletions
|
@ -446,7 +446,7 @@ func labelsToString(labels []prompbmarshal.Label) string {
|
|||
break
|
||||
}
|
||||
}
|
||||
if len(labelsCopy) <= 1 {
|
||||
if mname != "" && len(labelsCopy) <= 1 {
|
||||
return mname
|
||||
}
|
||||
b := []byte(mname)
|
||||
|
|
|
@ -7,6 +7,53 @@ import (
|
|||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||||
)
|
||||
|
||||
func TestLabelsToString(t *testing.T) {
|
||||
f := func(labels []prompbmarshal.Label, sExpected string) {
|
||||
t.Helper()
|
||||
s := labelsToString(labels)
|
||||
if s != sExpected {
|
||||
t.Fatalf("unexpected result;\ngot\n%s\nwant\n%s", s, sExpected)
|
||||
}
|
||||
}
|
||||
f(nil, "{}")
|
||||
f([]prompbmarshal.Label{
|
||||
{
|
||||
Name: "__name__",
|
||||
Value: "foo",
|
||||
},
|
||||
}, "foo")
|
||||
f([]prompbmarshal.Label{
|
||||
{
|
||||
Name: "foo",
|
||||
Value: "bar",
|
||||
},
|
||||
}, `{foo="bar"}`)
|
||||
f([]prompbmarshal.Label{
|
||||
{
|
||||
Name: "foo",
|
||||
Value: "bar",
|
||||
},
|
||||
{
|
||||
Name: "a",
|
||||
Value: "bc",
|
||||
},
|
||||
}, `{a="bc",foo="bar"}`)
|
||||
f([]prompbmarshal.Label{
|
||||
{
|
||||
Name: "foo",
|
||||
Value: "bar",
|
||||
},
|
||||
{
|
||||
Name: "__name__",
|
||||
Value: "xxx",
|
||||
},
|
||||
{
|
||||
Name: "a",
|
||||
Value: "bc",
|
||||
},
|
||||
}, `xxx{a="bc",foo="bar"}`)
|
||||
}
|
||||
|
||||
func TestApplyRelabelConfigs(t *testing.T) {
|
||||
f := func(config string, labels []prompbmarshal.Label, isFinalize bool, resultExpected []prompbmarshal.Label) {
|
||||
t.Helper()
|
||||
|
|
Loading…
Reference in a new issue