lib/promrelabel: add relabeling tests when the source label is missing

This commit is contained in:
Aliaksandr Valialkin 2022-10-17 14:47:52 +03:00
parent 00e4c7f265
commit c4a3d8b169
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -115,6 +115,12 @@ func TestApplyRelabelConfigs(t *testing.T) {
source_labels: ["foo"]
target_label: "bar"
regex: ".+"
`, `{xxx="yyy"}`, false, `{xxx="yyy"}`)
f(`
- action: replace
source_labels: ["foo"]
target_label: "xxx"
regex: ".+"
`, `{xxx="yyy"}`, false, `{xxx="yyy"}`)
})
t.Run("replace-if-miss", func(t *testing.T) {
@ -133,6 +139,16 @@ func TestApplyRelabelConfigs(t *testing.T) {
target_label: "bar"
replacement: "a-$1-b"
`, `{xxx="yyy"}`, false, `{bar="a-yyy;-b",xxx="yyy"}`)
f(`
- action: replace
source_labels: ["xxx", "foo"]
target_label: "xxx"
`, `{xxx="yyy"}`, false, `{xxx="yyy;"}`)
f(`
- action: replace
source_labels: ["foo"]
target_label: "xxx"
`, `{xxx="yyy"}`, false, `{}`)
})
t.Run("replace-if-hit", func(t *testing.T) {
f(`