forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_test.go
70 lines (58 loc) · 1.68 KB
/
slack_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
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 (
SLACK_URL string
)
func TestSlackNotifier(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()
SLACK_URL = utils.Params.GetString("SLACK_URL")
if SLACK_URL == "" {
t.Log("slack notifier testing skipped, missing SLACK_URL environment variable")
t.SkipNow()
}
slacker.Host = null.NewNullString(SLACK_URL)
slacker.Enabled = null.NewNullBool(true)
t.Run("Load slack", func(t *testing.T) {
slacker.Host = null.NewNullString(SLACK_URL)
slacker.Delay = 100 * time.Millisecond
slacker.Limits = 3
Add(slacker)
assert.Equal(t, "Hunter Long", slacker.Author)
assert.Equal(t, SLACK_URL, slacker.Host.String)
})
t.Run("slack Within Limits", func(t *testing.T) {
ok := slacker.CanSend()
assert.True(t, ok)
})
t.Run("slack OnSave", func(t *testing.T) {
_, err := slacker.OnSave()
assert.Nil(t, err)
})
t.Run("slack OnFailure", func(t *testing.T) {
_, err := slacker.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("slack OnSuccess", func(t *testing.T) {
_, err := slacker.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
}