2020-04-06 13:44:03 +02:00
|
|
|
package main
|
2020-03-29 00:48:30 +01:00
|
|
|
|
|
|
|
import (
|
2020-04-01 17:17:53 +02:00
|
|
|
"net/url"
|
|
|
|
"os"
|
2020-03-29 00:48:30 +01:00
|
|
|
"testing"
|
2020-04-01 17:17:53 +02:00
|
|
|
|
2020-04-06 13:44:03 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/notifier"
|
2020-03-29 00:48:30 +01:00
|
|
|
)
|
|
|
|
|
2020-04-01 17:17:53 +02:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
u, _ := url.Parse("https://victoriametrics.com/path")
|
2020-04-06 13:44:03 +02:00
|
|
|
notifier.InitTemplateFunc(u)
|
2020-04-01 17:17:53 +02:00
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
2020-03-29 00:48:30 +01:00
|
|
|
func TestParseGood(t *testing.T) {
|
|
|
|
if _, err := Parse([]string{"testdata/*good.rules", "testdata/dir/*good.*"}, true); err != nil {
|
|
|
|
t.Errorf("error parsing files %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseBad(t *testing.T) {
|
|
|
|
if _, err := Parse([]string{"testdata/rules0-bad.rules"}, true); err == nil {
|
|
|
|
t.Errorf("expected syntaxt error")
|
|
|
|
}
|
|
|
|
if _, err := Parse([]string{"testdata/dir/rules0-bad.rules"}, true); err == nil {
|
|
|
|
t.Errorf("expected template annotation error")
|
|
|
|
}
|
|
|
|
if _, err := Parse([]string{"testdata/dir/rules1-bad.rules"}, true); err == nil {
|
|
|
|
t.Errorf("expected same group error")
|
|
|
|
}
|
2020-04-26 12:53:57 +02:00
|
|
|
if _, err := Parse([]string{"testdata/dir/rules2-bad.rules"}, true); err == nil {
|
|
|
|
t.Errorf("expected template label error")
|
|
|
|
}
|
2020-03-29 00:48:30 +01:00
|
|
|
if _, err := Parse([]string{"testdata/*.yaml"}, true); err == nil {
|
|
|
|
t.Errorf("expected empty group")
|
|
|
|
}
|
|
|
|
}
|