statping/notifiers/discord_test.go

74 lines
1.8 KiB
Go
Raw Normal View History

2020-03-25 18:46:50 +00:00
package notifiers
import (
"github.com/statping/statping/database"
"github.com/statping/statping/types/core"
"github.com/statping/statping/types/failures"
2020-03-25 18:46:50 +00:00
"github.com/statping/statping/types/notifications"
"github.com/statping/statping/types/null"
"github.com/statping/statping/types/services"
2020-04-16 09:57:00 +00:00
"github.com/statping/statping/utils"
2020-03-25 18:46:50 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)
var (
2020-06-04 23:18:37 +00:00
DISCORD_URL string
2020-03-25 18:46:50 +00:00
)
func TestDiscordNotifier(t *testing.T) {
t.Parallel()
2020-06-04 22:59:31 +00:00
err := utils.InitLogs()
require.Nil(t, err)
2020-06-04 23:18:37 +00:00
DISCORD_URL = utils.Params.GetString("DISCORD_URL")
2020-03-25 18:46:50 +00:00
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(&notifications.Notification{})
notifications.SetDB(db)
core.Example()
2020-03-25 18:46:50 +00:00
if DISCORD_URL == "" {
t.Log("discord notifier testing skipped, missing DISCORD_URL environment variable")
t.SkipNow()
}
t.Run("Load discord", func(t *testing.T) {
Discorder.Host = null.NewNullString(DISCORD_URL)
2020-03-25 18:46:50 +00:00
Discorder.Delay = time.Duration(100 * time.Millisecond)
Discorder.Enabled = null.NewNullBool(true)
Add(Discorder)
assert.Equal(t, "Hunter Long", Discorder.Author)
assert.Equal(t, DISCORD_URL, Discorder.Host.String)
2020-03-25 18:46:50 +00:00
})
t.Run("discord Notifier Tester", func(t *testing.T) {
assert.True(t, Discorder.CanSend())
})
t.Run("discord Notifier Tester OnSave", func(t *testing.T) {
_, err := Discorder.OnSave()
assert.Nil(t, err)
})
2020-03-25 18:46:50 +00:00
t.Run("discord OnFailure", func(t *testing.T) {
_, err := Discorder.OnFailure(services.Example(false), failures.Example())
2020-03-25 18:46:50 +00:00
assert.Nil(t, err)
})
t.Run("discord OnSuccess", func(t *testing.T) {
_, err := Discorder.OnSuccess(services.Example(true))
2020-03-25 18:46:50 +00:00
assert.Nil(t, err)
})
t.Run("discord Test", func(t *testing.T) {
2020-04-13 11:30:16 +00:00
_, err := Discorder.OnTest()
2020-03-25 18:46:50 +00:00
assert.Nil(t, err)
})
}