2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
|
|
|
import "testing"
|
2016-11-03 01:50:16 +00:00
|
|
|
import "github.com/influxdata/chronograf"
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
func TestValidateAlert(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
service string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test valid template alert",
|
2017-02-09 06:10:23 +00:00
|
|
|
service: ".slack()",
|
2016-11-03 00:59:25 +00:00
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test invalid template alert",
|
2017-02-09 06:10:23 +00:00
|
|
|
service: ".invalid()",
|
2016-11-03 00:59:25 +00:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
if err := ValidateAlert(tt.service); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("%q. ValidateAlert() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_validateTick(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2016-11-03 01:50:16 +00:00
|
|
|
script chronograf.TICKScript
|
2016-11-03 00:59:25 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
2016-11-03 01:50:16 +00:00
|
|
|
name: "Valid Script",
|
|
|
|
script: "stream|from()",
|
2016-11-03 00:59:25 +00:00
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2016-11-03 01:50:16 +00:00
|
|
|
name: "Invalid Script",
|
|
|
|
script: "stream|nothing",
|
2016-11-03 00:59:25 +00:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2016-11-03 01:50:16 +00:00
|
|
|
if err := validateTick(tt.script); (err != nil) != tt.wantErr {
|
2016-11-03 00:59:25 +00:00
|
|
|
t.Errorf("%q. validateTick() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|