forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegram_test.go
81 lines (65 loc) · 2.13 KB
/
telegram_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package notifiers
import (
"github.com/statping/statping/database"
"github.com/statping/statping/types/core"
"github.com/statping/statping/types/failures"
"github.com/statping/statping/types/notifications"
"github.com/statping/statping/types/null"
"github.com/statping/statping/types/services"
"github.com/statping/statping/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)
var (
telegramToken string
telegramChannel string
)
func TestTelegramNotifier(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
t.Parallel()
telegramToken = utils.Params.GetString("TELEGRAM_TOKEN")
telegramChannel = utils.Params.GetString("TELEGRAM_CHANNEL")
if telegramToken == "" || telegramChannel == "" {
t.Log("Telegram notifier testing skipped, missing TELEGRAM_TOKEN and TELEGRAM_CHANNEL environment variable")
t.SkipNow()
}
Telegram.ApiSecret = null.NewNullString(telegramToken)
Telegram.Var1 = null.NewNullString(telegramChannel)
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(¬ifications.Notification{})
notifications.SetDB(db)
core.Example()
t.Run("Load Telegram", func(t *testing.T) {
Telegram.ApiSecret = null.NewNullString(telegramToken)
Telegram.Var1 = null.NewNullString(telegramChannel)
Telegram.Delay = time.Duration(1 * time.Second)
Telegram.Enabled = null.NewNullBool(true)
Add(Telegram)
assert.Equal(t, "Hunter Long", Telegram.Author)
assert.Equal(t, telegramToken, Telegram.ApiSecret.String)
assert.Equal(t, telegramChannel, Telegram.Var1.String)
})
t.Run("Telegram Within Limits", func(t *testing.T) {
assert.True(t, Telegram.CanSend())
})
t.Run("Telegram OnSave", func(t *testing.T) {
_, err := Telegram.OnSave()
assert.Nil(t, err)
})
t.Run("Telegram OnFailure", func(t *testing.T) {
_, err := Telegram.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("Telegram OnSuccess", func(t *testing.T) {
_, err := Telegram.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("Telegram Test", func(t *testing.T) {
_, err := Telegram.OnTest()
assert.Nil(t, err)
})
}