forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwilio_test.go
81 lines (65 loc) · 2.04 KB
/
twilio_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-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 (
TWILIO_SID string
TWILIO_SECRET string
)
func TestTwilioNotifier(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()
TWILIO_SID = utils.Params.GetString("TWILIO_SID")
TWILIO_SECRET = utils.Params.GetString("TWILIO_SECRET")
if TWILIO_SID == "" || TWILIO_SECRET == "" {
t.Log("twilio notifier testing skipped, missing TWILIO_SID and TWILIO_SECRET environment variable")
t.SkipNow()
}
t.Run("Load Twilio", func(t *testing.T) {
Twilio.ApiKey = null.NewNullString(TWILIO_SID)
Twilio.ApiSecret = null.NewNullString(TWILIO_SECRET)
Twilio.Var1 = null.NewNullString("15005550006")
Twilio.Var2 = null.NewNullString("15005550006")
Twilio.Delay = 100 * time.Millisecond
Twilio.Enabled = null.NewNullBool(true)
Add(Twilio)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", Twilio.Author)
assert.Equal(t, TWILIO_SID, Twilio.ApiKey.String)
})
t.Run("Twilio Within Limits", func(t *testing.T) {
assert.True(t, Twilio.CanSend())
})
t.Run("Twilio OnSave", func(t *testing.T) {
_, err := Twilio.OnSave()
assert.Nil(t, err)
})
t.Run("Twilio OnFailure", func(t *testing.T) {
_, err := Twilio.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("Twilio OnSuccess", func(t *testing.T) {
_, err := Twilio.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("Twilio Test", func(t *testing.T) {
_, err := Twilio.OnTest()
assert.Nil(t, err)
})
}