From c4a3d8b1696bad4c601526b260dd6d49bf97f745 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 17 Oct 2022 14:47:52 +0300 Subject: [PATCH] lib/promrelabel: add relabeling tests when the source label is missing --- lib/promrelabel/relabel_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index a412eed8a8..8c1d34064f 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -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(`