71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package notifiers
|
|
|
|
import (
|
|
"github.com/statping-ng/statping-ng/database"
|
|
"github.com/statping-ng/statping-ng/types/core"
|
|
"github.com/statping-ng/statping-ng/types/failures"
|
|
"github.com/statping-ng/statping-ng/types/notifications"
|
|
"github.com/statping-ng/statping-ng/types/null"
|
|
"github.com/statping-ng/statping-ng/types/services"
|
|
"github.com/statping-ng/statping-ng/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
SLACK_URL string
|
|
)
|
|
|
|
func TestSlackNotifier(t *testing.T) {
|
|
err := utils.InitLogs()
|
|
require.Nil(t, err)
|
|
|
|
t.Parallel()
|
|
db, err := database.OpenTester()
|
|
require.Nil(t, err)
|
|
db.AutoMigrate(¬ifications.Notification{})
|
|
notifications.SetDB(db)
|
|
core.Example()
|
|
|
|
SLACK_URL = utils.Params.GetString("SLACK_URL")
|
|
if SLACK_URL == "" {
|
|
t.Log("slack notifier testing skipped, missing SLACK_URL environment variable")
|
|
t.SkipNow()
|
|
}
|
|
|
|
slacker.Host = null.NewNullString(SLACK_URL)
|
|
slacker.Enabled = null.NewNullBool(true)
|
|
|
|
t.Run("Load slack", func(t *testing.T) {
|
|
slacker.Host = null.NewNullString(SLACK_URL)
|
|
slacker.Delay = 100 * time.Millisecond
|
|
slacker.Limits = 3
|
|
Add(slacker)
|
|
assert.Equal(t, "Hunter Long", slacker.Author)
|
|
assert.Equal(t, SLACK_URL, slacker.Host.String)
|
|
})
|
|
|
|
t.Run("slack Within Limits", func(t *testing.T) {
|
|
ok := slacker.CanSend()
|
|
assert.True(t, ok)
|
|
})
|
|
|
|
t.Run("slack OnSave", func(t *testing.T) {
|
|
_, err := slacker.OnSave()
|
|
assert.Nil(t, err)
|
|
})
|
|
|
|
t.Run("slack OnFailure", func(t *testing.T) {
|
|
_, err := slacker.OnFailure(services.Example(false), failures.Example())
|
|
assert.Nil(t, err)
|
|
})
|
|
|
|
t.Run("slack OnSuccess", func(t *testing.T) {
|
|
_, err := slacker.OnSuccess(services.Example(true))
|
|
assert.Nil(t, err)
|
|
})
|
|
|
|
}
|