mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 21:54:10 -08:00
test the labelTarget regex to make sure it properly validates pre-interpolated label names.
This commit is contained in:
parent
f867c1fd58
commit
ec6524ce74
|
@ -512,6 +512,34 @@ func TestEmptyGlobalBlock(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTargetLabelValidity(t *testing.T) {
|
||||
tests := []struct {
|
||||
str string
|
||||
valid bool
|
||||
}{
|
||||
{"-label", false},
|
||||
{"label", true},
|
||||
{"label${1}", true},
|
||||
{"${1}label", true},
|
||||
{"${1}", true},
|
||||
{"${1}label", true},
|
||||
{"${", false},
|
||||
{"$", false},
|
||||
{"${}", false},
|
||||
{"foo${", false},
|
||||
{"$1", true},
|
||||
{"asd$2asd", true},
|
||||
{"-foo${1}bar-", false},
|
||||
{"_${1}_", true},
|
||||
{"foo${bar}foo", true},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if relabelTarget.Match([]byte(test.str)) != test.valid {
|
||||
t.Fatalf("Expected %q to be %v", test.str, test.valid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func kubernetesSDHostURL() URL {
|
||||
tURL, _ := url.Parse("https://localhost:1234")
|
||||
return URL{URL: tURL}
|
||||
|
|
Loading…
Reference in a new issue