mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
da60a68d09
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>
40 lines
958 B
Go
40 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
|
|
}
|
|
}
|