statping/handlers/notifiers_test.go

61 lines
1.4 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package handlers
import (
2020-03-09 18:17:55 +00:00
"github.com/statping/statping/notifiers"
"github.com/statping/statping/types/services"
2020-03-08 18:13:27 +00:00
"github.com/stretchr/testify/assert"
2020-03-04 10:29:00 +00:00
"testing"
)
2020-03-08 21:32:26 +00:00
func TestAttachment(t *testing.T) {
2020-03-15 21:36:55 +00:00
notifiers.InitNotifiers()
2020-03-08 21:32:26 +00:00
}
2020-03-04 10:29:00 +00:00
func TestApiNotifiersRoutes(t *testing.T) {
tests := []HTTPTest{
{
Name: "Statping Notifiers",
URL: "/api/notifiers",
Method: "GET",
ExpectedStatus: 200,
ResponseLen: len(services.AllNotifiers()),
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
}, {
Name: "Statping Slack Notifier",
URL: "/api/notifier/slack",
2020-03-04 10:29:00 +00:00
Method: "GET",
ExpectedStatus: 200,
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
}, {
Name: "Statping Update Notifier",
URL: "/api/notifier/slack",
2020-03-04 10:29:00 +00:00
Method: "POST",
Body: `{
"method": "slack",
"host": "https://slack.api/example/12345",
2020-03-08 18:13:27 +00:00
"enabled": true,
"limits": 55
}`,
2020-03-04 10:29:00 +00:00
ExpectedStatus: 200,
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
}, {
Name: "Statping Slack Notifier",
URL: "/api/notifier/slack",
2020-03-19 01:50:53 +00:00
Method: "GET",
ExpectedStatus: 200,
ExpectedContains: []string{`"method":"slack"`},
2020-03-19 01:50:53 +00:00
BeforeTest: SetTestENV,
SecureRoute: true,
2020-03-04 10:29:00 +00:00
}}
for _, v := range tests {
t.Run(v.Name, func(t *testing.T) {
_, t, err := RunHTTPTest(v, t)
2020-03-08 18:13:27 +00:00
assert.Nil(t, err)
2020-03-04 10:29:00 +00:00
})
}
}