forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushover_test.go
78 lines (63 loc) · 2.05 KB
/
pushover_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
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"
)
var (
PUSHOVER_TOKEN string
PUSHOVER_API string
)
func TestPushoverNotifier(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
t.Parallel()
PUSHOVER_TOKEN = utils.Params.GetString("PUSHOVER_TOKEN")
PUSHOVER_API = utils.Params.GetString("PUSHOVER_API")
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(¬ifications.Notification{})
notifications.SetDB(db)
core.Example()
if PUSHOVER_TOKEN == "" || PUSHOVER_API == "" {
t.Log("Pushover notifier testing skipped, missing PUSHOVER_TOKEN and PUSHOVER_API environment variable")
t.SkipNow()
}
t.Run("Load Pushover", func(t *testing.T) {
Pushover.ApiKey = null.NewNullString(PUSHOVER_TOKEN)
Pushover.ApiSecret = null.NewNullString(PUSHOVER_API)
Pushover.Var1 = null.NewNullString("Normal")
Pushover.Var2 = null.NewNullString("vibrate")
Pushover.Enabled = null.NewNullBool(true)
Add(Pushover)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", Pushover.Author)
assert.Equal(t, PUSHOVER_TOKEN, Pushover.ApiKey.String)
})
t.Run("Pushover Within Limits", func(t *testing.T) {
assert.True(t, Pushover.CanSend())
})
t.Run("Pushover OnSave", func(t *testing.T) {
_, err := Pushover.OnSave()
assert.Nil(t, err)
})
t.Run("Pushover OnFailure", func(t *testing.T) {
_, err := Pushover.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("Pushover OnSuccess", func(t *testing.T) {
_, err := Pushover.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("Pushover Test", func(t *testing.T) {
_, err := Pushover.OnTest()
assert.Nil(t, err)
})
}