From 6eb205f8b052ca0155a844599d2d134a8c776bb4 Mon Sep 17 00:00:00 2001 From: hagen1778 <roman@victoriametrics.com> Date: Thu, 2 Nov 2023 15:28:39 +0100 Subject: [PATCH] app/vmalert: verify alert name correctness in restore test Signed-off-by: hagen1778 <roman@victoriametrics.com> --- app/vmalert/rule/alerting_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/vmalert/rule/alerting_test.go b/app/vmalert/rule/alerting_test.go index c220674e9f..b6496c688e 100644 --- a/app/vmalert/rule/alerting_test.go +++ b/app/vmalert/rule/alerting_test.go @@ -640,6 +640,9 @@ func TestGroup_Restore(t *testing.T) { if got.ActiveAt != exp.ActiveAt { t.Fatalf("expected ActiveAt %v; got %v", exp.ActiveAt, got.ActiveAt) } + if got.Name != exp.Name { + t.Fatalf("expected alertname %q; got %q", exp.Name, got.Name) + } } } @@ -655,6 +658,7 @@ func TestGroup_Restore(t *testing.T) { []config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}}, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): { + Name: "foo", ActiveAt: defaultTS, }, }) @@ -668,6 +672,7 @@ func TestGroup_Restore(t *testing.T) { []config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}}, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): { + Name: "foo", ActiveAt: ts, }, }) @@ -683,9 +688,11 @@ func TestGroup_Restore(t *testing.T) { }, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): { + Name: "foo", ActiveAt: defaultTS, }, hash(map[string]string{alertNameLabel: "bar", alertGroupNameLabel: "TestRestore"}): { + Name: "bar", ActiveAt: ts, }, }) @@ -703,9 +710,11 @@ func TestGroup_Restore(t *testing.T) { }, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): { + Name: "foo", ActiveAt: ts, }, hash(map[string]string{alertNameLabel: "bar", alertGroupNameLabel: "TestRestore"}): { + Name: "bar", ActiveAt: ts, }, }) @@ -718,6 +727,7 @@ func TestGroup_Restore(t *testing.T) { []config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}}, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): { + Name: "foo", ActiveAt: defaultTS, }, }) @@ -730,6 +740,7 @@ func TestGroup_Restore(t *testing.T) { []config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutils.NewDuration(time.Second)}}, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore", "env": "dev"}): { + Name: "foo", ActiveAt: ts, }, }) @@ -742,6 +753,7 @@ func TestGroup_Restore(t *testing.T) { []config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutils.NewDuration(time.Second)}}, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore", "env": "dev"}): { + Name: "foo", ActiveAt: defaultTS, }, })