2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
import "github.com/influxdata/chronograf"
|
|
|
|
|
|
|
|
func TestInfluxOut(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
want chronograf.TICKScript
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test influxDBOut kapacitor node",
|
|
|
|
want: `trigger
|
2016-11-04 21:35:12 +00:00
|
|
|
|eval(lambda: "usage_user")
|
2016-11-04 01:56:42 +00:00
|
|
|
.as('value')
|
2016-11-03 00:59:25 +00:00
|
|
|
|influxDBOut()
|
|
|
|
.create()
|
|
|
|
.database(output_db)
|
|
|
|
.retentionPolicy(output_rp)
|
|
|
|
.measurement(output_mt)
|
2016-11-03 22:27:58 +00:00
|
|
|
.tag('alertName', name)
|
2016-11-03 19:21:17 +00:00
|
|
|
.tag('triggerType', triggerType)
|
2016-11-03 00:59:25 +00:00
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2016-11-04 21:28:28 +00:00
|
|
|
got, err := InfluxOut(chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "deadman",
|
2016-11-04 21:28:28 +00:00
|
|
|
Query: chronograf.QueryConfig{
|
|
|
|
Fields: []struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Funcs []string `json:"funcs"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Field: "usage_user",
|
|
|
|
Funcs: []string{"mean"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-11-03 18:41:34 +00:00
|
|
|
})
|
2016-11-04 21:28:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%q. InfluxOut()) error = %v", tt.name, err)
|
|
|
|
continue
|
|
|
|
}
|
2016-11-03 00:59:25 +00:00
|
|
|
formatted, err := formatTick(got)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%q. formatTick() error = %v", tt.name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if formatted != tt.want {
|
|
|
|
t.Errorf("%q. InfluxOut() = %v, want %v", tt.name, formatted, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|