VictoriaMetrics/app/vmalert/unitest_test.go
Haleygo da60a68d09
vmalert: init unit test (#4596)
vmalert: support unit tests

See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2945 
---------

Signed-off-by: hagen1778 <roman@victoriametrics.com>
Co-authored-by: hagen1778 <roman@victoriametrics.com>
2023-07-20 15:07:10 +02:00

41 lines
958 B
Go

package main
import (
"testing"
)
func TestUnitRule(t *testing.T) {
testCases := []struct {
name string
disableGroupLabel bool
files []string
failed bool
}{
{
name: "run multi files",
files: []string{"./unittest/testdata/test1.yaml", "./unittest/testdata/test2.yaml"},
failed: false,
},
{
name: "disable group label",
disableGroupLabel: true,
files: []string{"./unittest/testdata/disable-group-label.yaml"},
failed: false,
},
{
name: "failing test",
files: []string{"./unittest/testdata/failed-test.yaml"},
failed: true,
},
}
for _, tc := range testCases {
oldFlag := *disableAlertGroupLabel
*disableAlertGroupLabel = tc.disableGroupLabel
fail := unitRule(tc.files...)
if fail != tc.failed {
t.Fatalf("failed to test %s, expect %t, got %t", tc.name, tc.failed, fail)
}
*disableAlertGroupLabel = oldFlag
}
}