forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile_test.go
120 lines (103 loc) · 3.06 KB
/
mobile_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Statping
// Copyright (C) 2018. Hunter Long and the project contributors
// Written by Hunter Long <[email protected]> and the project contributors
//
// https://github.com/hunterlong/statping
//
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package notifiers
import (
"github.com/hunterlong/statping/core/notifier"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
var (
MOBILE_ID string
MOBILE_NUMBER string
)
func init() {
MOBILE_ID = os.Getenv("MOBILE_ID")
MOBILE_NUMBER = os.Getenv("MOBILE_NUMBER")
mobile.Var1 = MOBILE_ID
}
func TestMobileNotifier(t *testing.T) {
t.Parallel()
mobile.Var1 = MOBILE_ID
mobile.Var2 = os.Getenv("MOBILE_NUMBER")
if MOBILE_ID == "" {
t.Log("mobile notifier testing skipped, missing MOBILE_ID environment variable")
t.SkipNow()
}
currentCount = CountNotifiers()
t.Run("Load mobile", func(t *testing.T) {
mobile.Var1 = MOBILE_ID
mobile.Var2 = MOBILE_NUMBER
mobile.Delay = time.Duration(100 * time.Millisecond)
mobile.Limits = 10
err := notifier.AddNotifier(mobile)
assert.Nil(t, err)
assert.Equal(t, "Hunter Long", mobile.Author)
assert.Equal(t, MOBILE_ID, mobile.Var1)
assert.Equal(t, MOBILE_NUMBER, mobile.Var2)
})
t.Run("Load mobile Notifier", func(t *testing.T) {
notifier.Load()
})
t.Run("mobile Notifier Tester", func(t *testing.T) {
assert.True(t, mobile.CanTest())
})
t.Run("mobile Within Limits", func(t *testing.T) {
ok, err := mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("mobile OnFailure", func(t *testing.T) {
mobile.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(mobile.Queue))
})
t.Run("mobile OnFailure multiple times", func(t *testing.T) {
for i := 0; i <= 5; i++ {
mobile.OnFailure(TestService, TestFailure)
}
assert.Equal(t, 7, len(mobile.Queue))
})
t.Run("mobile OnSuccess", func(t *testing.T) {
mobile.OnSuccess(TestService)
assert.Equal(t, 7, len(mobile.Queue))
})
t.Run("mobile OnSuccess Again", func(t *testing.T) {
t.SkipNow()
assert.True(t, TestService.Online)
mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(mobile.Queue))
go notifier.Queue(mobile)
time.Sleep(20 * time.Second)
assert.Equal(t, 1, len(mobile.Queue))
})
t.Run("mobile Within Limits again", func(t *testing.T) {
ok, err := mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
t.Run("mobile Test", func(t *testing.T) {
t.SkipNow()
err := mobile.OnTest()
assert.Nil(t, err)
})
t.Run("mobile Queue", func(t *testing.T) {
t.SkipNow()
go notifier.Queue(mobile)
time.Sleep(15 * time.Second)
assert.Equal(t, MOBILE_ID, mobile.Var1)
assert.Equal(t, 0, len(mobile.Queue))
})
}