forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon_sns_test.go
76 lines (62 loc) · 2.17 KB
/
amazon_sns_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
package notifiers
import (
"testing"
"time"
"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"
)
func TestAmazonSNSNotifier(t *testing.T) {
err := utils.InitLogs()
require.Nil(t, err)
snsToken := utils.Params.GetString("SNS_TOKEN")
snsSecret := utils.Params.GetString("SNS_SECRET")
snsRegion := utils.Params.GetString("SNS_REGION")
snsTopic := utils.Params.GetString("SNS_TOPIC")
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(¬ifications.Notification{})
notifications.SetDB(db)
core.Example()
if snsToken == "" || snsSecret == "" || snsRegion == "" || snsTopic == "" {
t.Log("SNS notifier testing skipped, missing SNS_TOKEN, SNS_SECRET, SNS_REGION, SNS_TOPIC environment variables")
t.SkipNow()
}
t.Run("Load SNS", func(t *testing.T) {
AmazonSNS.ApiKey = null.NewNullString(snsToken)
AmazonSNS.ApiSecret = null.NewNullString(snsSecret)
AmazonSNS.Var1 = null.NewNullString(snsRegion)
AmazonSNS.Host = null.NewNullString(snsTopic)
AmazonSNS.Delay = 15 * time.Second
AmazonSNS.Enabled = null.NewNullBool(true)
Add(AmazonSNS)
assert.Equal(t, "Hunter Long", AmazonSNS.Author)
assert.Equal(t, snsToken, AmazonSNS.ApiKey.String)
assert.Equal(t, snsSecret, AmazonSNS.ApiSecret.String)
})
t.Run("SNS Notifier Tester", func(t *testing.T) {
assert.True(t, AmazonSNS.CanSend())
})
t.Run("SNS Notifier Tester OnSave", func(t *testing.T) {
_, err := AmazonSNS.OnSave()
assert.Nil(t, err)
})
t.Run("SNS OnFailure", func(t *testing.T) {
_, err := AmazonSNS.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("SNS OnSuccess", func(t *testing.T) {
_, err := AmazonSNS.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("SNS Test", func(t *testing.T) {
_, err := AmazonSNS.OnTest()
assert.Nil(t, err)
})
}