relabel: check validity of all test cases

Thought this would be a nice check on the `Validate()` function, but
some of the test cases needed tweaking to pass.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-12-18 15:03:21 +00:00
parent 2d4c367d87
commit 000182e4b8

View File

@ -335,7 +335,7 @@ func TestRelabel(t *testing.T) {
}, },
{ // invalid target_labels { // invalid target_labels
input: labels.FromMap(map[string]string{ input: labels.FromMap(map[string]string{
"a": "some-name-value", "a": "some-name-0",
}), }),
relabel: []*Config{ relabel: []*Config{
{ {
@ -350,18 +350,18 @@ func TestRelabel(t *testing.T) {
Regex: MustNewRegexp("some-([^-]+)-([^,]+)"), Regex: MustNewRegexp("some-([^-]+)-([^,]+)"),
Action: Replace, Action: Replace,
Replacement: "${1}", Replacement: "${1}",
TargetLabel: "0${3}", TargetLabel: "${3}",
}, },
{ {
SourceLabels: model.LabelNames{"a"}, SourceLabels: model.LabelNames{"a"},
Regex: MustNewRegexp("some-([^-]+)-([^,]+)"), Regex: MustNewRegexp("some-([^-]+)(-[^,]+)"),
Action: Replace, Action: Replace,
Replacement: "${1}", Replacement: "${1}",
TargetLabel: "-${3}", TargetLabel: "${3}",
}, },
}, },
output: labels.FromMap(map[string]string{ output: labels.FromMap(map[string]string{
"a": "some-name-value", "a": "some-name-0",
}), }),
}, },
{ // more complex real-life like usecase { // more complex real-life like usecase
@ -566,6 +566,7 @@ func TestRelabel(t *testing.T) {
if cfg.Replacement == "" { if cfg.Replacement == "" {
cfg.Replacement = DefaultRelabelConfig.Replacement cfg.Replacement = DefaultRelabelConfig.Replacement
} }
require.NoError(t, cfg.Validate())
} }
res, keep := Process(test.input, test.relabel...) res, keep := Process(test.input, test.relabel...)