From 60ffbcbb99507c5d88bdc857b02b3f43166d1ac6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 3 May 2021 11:26:38 +0300 Subject: [PATCH] lib/promrelabel: add tests for removing the specified {label="value"} pair --- lib/promrelabel/relabel_test.go | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index c8033877a8..58c51c81e4 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -121,6 +121,56 @@ func TestApplyRelabelConfigs(t *testing.T) { }, }) }) + t.Run("replace-remove-label-value-hit", func(t *testing.T) { + f(` +- action: replace + source_labels: ["foo"] + target_label: "foo" + regex: "xxx" + replacement: "" +`, []prompbmarshal.Label{ + { + Name: "foo", + Value: "xxx", + }, + { + Name: "bar", + Value: "baz", + }, + }, false, []prompbmarshal.Label{ + { + Name: "bar", + Value: "baz", + }, + }) + }) + t.Run("replace-remove-label-value-miss", func(t *testing.T) { + f(` +- action: replace + source_labels: ["foo"] + target_label: "foo" + regex: "xxx" + replacement: "" +`, []prompbmarshal.Label{ + { + Name: "foo", + Value: "yyy", + }, + { + Name: "bar", + Value: "baz", + }, + }, false, []prompbmarshal.Label{ + { + Name: "bar", + Value: "baz", + }, + { + Name: "foo", + Value: "yyy", + }, + }) + }) t.Run("replace-hit-target-label-with-capture-group", func(t *testing.T) { f(` - action: replace