closes #1289 Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Rename internals struct. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update changelog. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update READMEs and CHANGELOG. Signed-off-by: François de Metz <francois@stormz.me> Signed-off-by: Cyril Duez <cyril@stormz.me> Update SampleConfig. Update the config format. Update telegraf config. Update the webhooks README. Update changelog. Update the changelog with an upgrade path. Update default ports. Fix indent. Check for nil value on AvailableWebhooks. Check for CanInterface.
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package rollbar
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
)
|
|
|
|
func postWebhooks(rb *RollbarWebhook, eventBody string) *httptest.ResponseRecorder {
|
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody))
|
|
w := httptest.NewRecorder()
|
|
w.Code = 500
|
|
|
|
rb.eventHandler(w, req)
|
|
|
|
return w
|
|
}
|
|
|
|
func TestNewItem(t *testing.T) {
|
|
var acc testutil.Accumulator
|
|
rb := &RollbarWebhook{Path: "/rollbar", acc: &acc}
|
|
resp := postWebhooks(rb, NewItemJSON())
|
|
if resp.Code != http.StatusOK {
|
|
t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
|
}
|
|
|
|
fields := map[string]interface{}{
|
|
"id": 272716944,
|
|
}
|
|
|
|
tags := map[string]string{
|
|
"event": "new_item",
|
|
"environment": "production",
|
|
"project_id": "90",
|
|
"language": "python",
|
|
"level": "error",
|
|
}
|
|
|
|
acc.AssertContainsTaggedFields(t, "rollbar_webhooks", fields, tags)
|
|
}
|
|
|
|
func TestDeploy(t *testing.T) {
|
|
var acc testutil.Accumulator
|
|
rb := &RollbarWebhook{Path: "/rollbar", acc: &acc}
|
|
resp := postWebhooks(rb, DeployJSON())
|
|
if resp.Code != http.StatusOK {
|
|
t.Errorf("POST deploy returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
|
}
|
|
|
|
fields := map[string]interface{}{
|
|
"id": 187585,
|
|
}
|
|
|
|
tags := map[string]string{
|
|
"event": "deploy",
|
|
"environment": "production",
|
|
"project_id": "90",
|
|
}
|
|
|
|
acc.AssertContainsTaggedFields(t, "rollbar_webhooks", fields, tags)
|
|
}
|
|
|
|
func TestUnknowItem(t *testing.T) {
|
|
rb := &RollbarWebhook{Path: "/rollbar"}
|
|
resp := postWebhooks(rb, UnknowJSON())
|
|
if resp.Code != http.StatusOK {
|
|
t.Errorf("POST unknow returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
|
}
|
|
}
|