influxdb/chronograf/.kapacitor/influxout_test.go

63 lines
1.3 KiB
Go
Raw Normal View History

2016-11-03 00:59:25 +00:00
package kapacitor
import "testing"
import "github.com/influxdata/influxdb/chronograf"
2016-11-03 00:59:25 +00:00
func TestInfluxOut(t *testing.T) {
tests := []struct {
name string
want chronograf.TICKScript
}{
{
name: "Test influxDBOut kapacitor node",
want: `trigger
|eval(lambda: "emitted")
.as('value')
.keep('value', messageField, durationField)
|eval(lambda: float("value"))
.as('value')
.keep()
2016-11-03 00:59:25 +00:00
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag('alertName', name)
.tag('triggerType', triggerType)
2016-11-03 00:59:25 +00:00
`,
},
}
for _, tt := range tests {
got, err := InfluxOut(chronograf.AlertRule{
Name: "name",
Trigger: "deadman",
Query: &chronograf.QueryConfig{
Fields: []chronograf.Field{
{
Value: "mean",
Type: "func",
Args: []chronograf.Field{
{
Value: "usage_user",
Type: "field",
},
},
},
},
},
})
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)
}
}
}