telegraf/plugins/inputs/webhooks/particle/particle_webhooks_test.go

26 lines
678 B
Go
Raw Normal View History

2016-07-31 23:56:28 +00:00
package particle
import (
2016-08-01 01:26:58 +00:00
"bytes"
2016-08-01 00:30:34 +00:00
"net/http"
"net/http/httptest"
"testing"
2016-07-31 23:56:28 +00:00
2016-08-01 00:30:34 +00:00
"github.com/influxdata/telegraf/testutil"
2016-07-31 23:56:28 +00:00
)
2016-08-01 01:26:58 +00:00
func ParticleWebhookRequest(event string, urlEncodedString string, t *testing.T) {
2016-07-31 23:56:28 +00:00
var acc testutil.Accumulator
2016-08-01 00:30:34 +00:00
pwh := &ParticleWebhook{Path: "/particle", acc: &acc}
2016-08-01 01:26:58 +00:00
req, _ := http.NewRequest("POST", "/particle", bytes.NewBufferString(urlEncodedString))
2016-07-31 23:56:28 +00:00
w := httptest.NewRecorder()
pwh.eventHandler(w, req)
if w.Code != http.StatusOK {
t.Errorf("POST "+event+" returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
}
}
2016-08-01 01:26:58 +00:00
func TestParticleEvent(t *testing.T) {
ParticleWebhookRequest("particle_event", NewEventURLEncoded(), t)
2016-08-01 00:30:34 +00:00
}