mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-24 19:30:06 +01:00
dc28196237
1. split package rule under /app/vmalert, expose needed objects 2. add vmalert-tool with unittest subcmd https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2945
48 lines
1023 B
Go
48 lines
1023 B
Go
package unittest
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/templates"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
if err := templates.Load([]string{}, true); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestUnitRule(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
disableGroupLabel bool
|
|
files []string
|
|
failed bool
|
|
}{
|
|
{
|
|
name: "run multi files",
|
|
files: []string{"./testdata/test1.yaml", "./testdata/test2.yaml"},
|
|
failed: false,
|
|
},
|
|
{
|
|
name: "disable group label",
|
|
disableGroupLabel: true,
|
|
files: []string{"./testdata/disable-group-label.yaml"},
|
|
failed: false,
|
|
},
|
|
{
|
|
name: "failing test",
|
|
files: []string{"./testdata/failed-test.yaml"},
|
|
failed: true,
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
fail := UnitTest(tc.files, tc.disableGroupLabel)
|
|
if fail != tc.failed {
|
|
t.Fatalf("failed to test %s, expect %t, got %t", tc.name, tc.failed, fail)
|
|
}
|
|
}
|
|
}
|