// Statping // Copyright (C) 2018. Hunter Long and the project contributors // Written by Hunter Long and the project contributors // // https://github.com/hunterlong/statping // // The licenses for most software and other practical works are designed // to take away your freedom to share and change the works. By contrast, // the GNU General Public License is intended to guarantee your freedom to // share and change all versions of a program--to make sure it remains free // software for all its users. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package notifiers import ( "github.com/statping/statping/database" "github.com/statping/statping/types/notifications" "github.com/statping/statping/types/null" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "os" "testing" "time" ) var ( DISCORD_URL = os.Getenv("DISCORD_URL") discordMessage = `{"content": "The discord notifier on Statping has been tested!"}` ) func init() { DISCORD_URL = os.Getenv("DISCORD_URL") } func TestDiscordNotifier(t *testing.T) { db, err := database.OpenTester() require.Nil(t, err) db.AutoMigrate(¬ifications.Notification{}) notifications.SetDB(db) 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 = DISCORD_URL 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) }) t.Run("discord Notifier Tester", func(t *testing.T) { assert.True(t, Discorder.CanSend()) }) t.Run("discord OnFailure", func(t *testing.T) { err := Discorder.OnFailure(exampleService, exampleFailure) assert.Nil(t, err) }) t.Run("discord OnSuccess", func(t *testing.T) { err := Discorder.OnSuccess(exampleService) assert.Nil(t, err) }) t.Run("discord Test", func(t *testing.T) { err := Discorder.OnTest() assert.Nil(t, err) }) }