influxdb/kapacitor/alerts_test.go

72 lines
1.4 KiB
Go
Raw Normal View History

2016-11-03 00:59:25 +00:00
package kapacitor
2016-11-01 00:19:32 +00:00
import (
"testing"
"github.com/influxdata/chronograf"
)
2016-11-03 00:59:25 +00:00
func TestAlertServices(t *testing.T) {
tests := []struct {
name string
2016-11-03 00:59:25 +00:00
rule chronograf.AlertRule
want chronograf.TICKScript
wantErr bool
}{
{
2016-11-03 00:59:25 +00:00
name: "Test several valid services",
rule: chronograf.AlertRule{
Alerts: []string{"slack", "victorops", "email"},
},
2016-11-03 00:59:25 +00:00
want: `alert()
.slack()
.victorOps()
.email()
`,
},
{
2016-11-03 00:59:25 +00:00
name: "Test single invalid services amongst several valid",
rule: chronograf.AlertRule{
Alerts: []string{"slack", "invalid", "email"},
},
2016-11-03 00:59:25 +00:00
want: ``,
wantErr: true,
},
{
2016-11-03 00:59:25 +00:00
name: "Test single invalid service",
rule: chronograf.AlertRule{
Alerts: []string{"invalid"},
},
2016-11-03 00:59:25 +00:00
want: ``,
wantErr: true,
},
{
2016-11-03 00:59:25 +00:00
name: "Test single valid service",
rule: chronograf.AlertRule{
Alerts: []string{"slack"},
},
2016-11-03 00:59:25 +00:00
want: `alert()
.slack()
`,
},
}
for _, tt := range tests {
2016-11-03 00:59:25 +00:00
got, err := AlertServices(tt.rule)
if (err != nil) != tt.wantErr {
2016-11-03 00:59:25 +00:00
t.Errorf("%q. AlertServices() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
}
2016-11-03 00:59:25 +00:00
if tt.wantErr {
continue
}
2016-11-03 00:59:25 +00:00
formatted, err := formatTick("alert()" + got)
if err != nil {
t.Errorf("%q. formatTick() error = %v", tt.name, err)
continue
}
2016-11-03 00:59:25 +00:00
if formatted != tt.want {
t.Errorf("%q. AlertServices() = %v, want %v", tt.name, formatted, tt.want)
}
}
}