forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
67 lines (55 loc) · 1.76 KB
/
command_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
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 TestCommandNotifier(t *testing.T) {
t.Parallel()
t.SkipNow()
err := utils.InitLogs()
require.Nil(t, err)
db, err := database.OpenTester()
require.Nil(t, err)
db.AutoMigrate(¬ifications.Notification{})
notifications.SetDB(db)
core.Example()
t.Run("Load Command", func(t *testing.T) {
Command.Host = null.NewNullString("/bin/echo")
Command.Var1 = null.NewNullString("service {{.Service.Domain}} is online")
Command.Var2 = null.NewNullString("service {{.Service.Domain}} is offline")
Command.Delay = time.Duration(100 * time.Millisecond)
Command.Limits = 99
Command.Enabled = null.NewNullBool(true)
Add(Command)
assert.Equal(t, "Hunter Long", Command.Author)
assert.Equal(t, "/bin/echo", Command.Host)
})
t.Run("Command Notifier Tester", func(t *testing.T) {
assert.True(t, Command.CanSend())
})
t.Run("Command OnSave", func(t *testing.T) {
_, err := Command.OnSave()
assert.Nil(t, err)
})
t.Run("Command OnFailure", func(t *testing.T) {
_, err := Command.OnFailure(services.Example(false), failures.Example())
assert.Nil(t, err)
})
t.Run("Command OnSuccess", func(t *testing.T) {
_, err := Command.OnSuccess(services.Example(true))
assert.Nil(t, err)
})
t.Run("Command Test", func(t *testing.T) {
_, err := Command.OnTest()
assert.Nil(t, err)
})
}