influxdb/kapacitor/validate_test.go

53 lines
1.0 KiB
Go
Raw Normal View History

2016-11-03 00:59:25 +00:00
package kapacitor
import "testing"
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",
service: ".slack()",
2016-11-03 00:59:25 +00:00
wantErr: false,
},
{
name: "Test invalid template alert",
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
script chronograf.TICKScript
2016-11-03 00:59:25 +00:00
wantErr bool
}{
{
name: "Valid Script",
script: "stream|from()",
2016-11-03 00:59:25 +00:00
wantErr: false,
},
{
name: "Invalid Script",
script: "stream|nothing",
2016-11-03 00:59:25 +00:00
wantErr: true,
},
}
for _, tt := range tests {
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)
}
}
}