forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_test.go
98 lines (82 loc) · 2.61 KB
/
email_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 (
EMAIL_HOST string
EMAIL_USER string
EMAIL_PASS string
EMAIL_OUTGOING string
EMAIL_SEND_TO string
EMAIL_PORT int64
)
func TestEmailNotifier(t *testing.T) {
t.Parallel()
err := utils.InitLogs()
require.Nil(t, err)
EMAIL_HOST = utils.Params.GetString("EMAIL_HOST")
EMAIL_USER = utils.Params.GetString("EMAIL_USER")
EMAIL_PASS = utils.Params.GetString("EMAIL_PASS")
EMAIL_OUTGOING = utils.Params.GetString("EMAIL_OUTGOING")
EMAIL_SEND_TO = utils.Params.GetString("EMAIL_SEND_TO")
EMAIL_PORT = utils.ToInt(utils.Params.GetString("EMAIL_PORT"))
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(¬ifications.Notification{})
notifications.SetDB(db)
core.Example()
if EMAIL_HOST == "" || EMAIL_USER == "" || EMAIL_PASS == "" {
t.Log("email notifier testing skipped, missing EMAIL_ environment variables")
t.SkipNow()
}
t.Run("New email", func(t *testing.T) {
email.Host = null.NewNullString(EMAIL_HOST)
email.Username = null.NewNullString(EMAIL_USER)
email.Password = null.NewNullString(EMAIL_PASS)
email.Var1 = null.NewNullString(EMAIL_OUTGOING)
email.Var2 = null.NewNullString(EMAIL_SEND_TO)
email.Port = null.NewNullInt64(EMAIL_PORT)
email.Delay = time.Duration(100 * time.Millisecond)
email.Enabled = null.NewNullBool(true)
Add(email)
assert.Equal(t, "Hunter Long", email.Author)
assert.Equal(t, EMAIL_HOST, email.Host.String)
})
t.Run("email Within Limits", func(t *testing.T) {
ok := email.CanSend()
assert.True(t, ok)
})
t.Run("email OnSave", func(t *testing.T) {
_, err := email.OnSave()
assert.Nil(t, err)
})
t.Run("email OnFailure", func(t *testing.T) {
_, err := email.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("email OnSuccess", func(t *testing.T) {
_, err := email.OnSuccess(services.Example(false))
assert.Nil(t, err)
})
t.Run("email Check Back Online", func(t *testing.T) {
assert.True(t, services.Example(true).Online)
})
t.Run("email OnSuccess Again", func(t *testing.T) {
_, err := email.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("email Test", func(t *testing.T) {
_, err := email.OnTest()
assert.Nil(t, err)
})
}