Check for nil value on AvailableWebhooks.

This commit is contained in:
François de Metz 2016-06-02 21:38:22 +02:00
parent 88274bdd05
commit c6b14833df
2 changed files with 32 additions and 1 deletions

View File

@ -75,7 +75,9 @@ func (wb *Webhooks) AvailableWebhooks() []Webhook {
f := s.Field(i)
if wbPlugin, ok := f.Interface().(Webhook); ok {
webhooks = append(webhooks, wbPlugin)
if !reflect.ValueOf(wbPlugin).IsNil() {
webhooks = append(webhooks, wbPlugin)
}
}
}

View File

@ -0,0 +1,29 @@
package webhooks
import (
"reflect"
"testing"
"github.com/influxdata/telegraf/plugins/inputs/webhooks/github"
"github.com/influxdata/telegraf/plugins/inputs/webhooks/rollbar"
)
func TestAvailableWebhooks(t *testing.T) {
wb := NewWebhooks()
expected := make([]Webhook, 0)
if !reflect.DeepEqual(wb.AvailableWebhooks(), expected) {
t.Errorf("expected to %v.\nGot %v", expected, wb.AvailableWebhooks())
}
wb.Github = &github.GithubWebhook{Path: "/github"}
expected = append(expected, wb.Github)
if !reflect.DeepEqual(wb.AvailableWebhooks(), expected) {
t.Errorf("expected to be %v.\nGot %v", expected, wb.AvailableWebhooks())
}
wb.Rollbar = &rollbar.RollbarWebhook{Path: "/rollbar"}
expected = append(expected, wb.Rollbar)
if !reflect.DeepEqual(wb.AvailableWebhooks(), expected) {
t.Errorf("expected to be %v.\nGot %v", expected, wb.AvailableWebhooks())
}
}