statping/notifiers/mobile_test.go

110 lines
2.8 KiB
Go
Raw Normal View History

2018-12-04 05:57:11 +00:00
// Statping
// Copyright (C) 2018. Hunter Long and the project contributors
// Written by Hunter Long <info@socialeck.com> and the project contributors
//
2018-12-04 04:17:29 +00:00
// 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 (
2018-12-04 04:17:29 +00:00
"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")
2019-10-25 15:13:32 +00:00
Mobile.Var1 = MOBILE_ID
}
func TestMobileNotifier(t *testing.T) {
t.Parallel()
2019-10-25 15:13:32 +00:00
Mobile.Var1 = MOBILE_ID
Mobile.Var2 = os.Getenv("MOBILE_NUMBER")
if MOBILE_ID == "" {
2019-10-25 15:13:32 +00:00
t.Log("Mobile notifier testing skipped, missing MOBILE_ID environment variable")
t.SkipNow()
}
currentCount = CountNotifiers()
2019-10-25 15:13:32 +00:00
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.AddNotifiers(Mobile)
assert.Nil(t, err)
2019-10-25 15:13:32 +00:00
assert.Equal(t, "Hunter Long", Mobile.Author)
assert.Equal(t, MOBILE_ID, Mobile.Var1)
assert.Equal(t, MOBILE_NUMBER, Mobile.Var2)
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile Notifier Tester", func(t *testing.T) {
assert.True(t, Mobile.CanTest())
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile Within Limits", func(t *testing.T) {
ok, err := Mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile OnFailure", func(t *testing.T) {
Mobile.OnFailure(TestService, TestFailure)
assert.Equal(t, 1, len(Mobile.Queue))
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile OnSuccess", func(t *testing.T) {
Mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(Mobile.Queue))
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile OnSuccess Again", func(t *testing.T) {
2018-12-14 17:34:42 +00:00
t.SkipNow()
assert.True(t, TestService.Online)
2019-10-25 15:13:32 +00:00
Mobile.OnSuccess(TestService)
assert.Equal(t, 1, len(Mobile.Queue))
go notifier.Queue(Mobile)
2018-12-14 10:13:35 +00:00
time.Sleep(20 * time.Second)
2019-10-25 15:13:32 +00:00
assert.Equal(t, 1, len(Mobile.Queue))
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile Within Limits again", func(t *testing.T) {
ok, err := Mobile.WithinLimits()
assert.Nil(t, err)
assert.True(t, ok)
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile Test", func(t *testing.T) {
t.SkipNow()
2019-10-25 15:13:32 +00:00
err := Mobile.OnTest()
assert.Nil(t, err)
})
2019-10-25 15:13:32 +00:00
t.Run("Mobile Queue", func(t *testing.T) {
2018-12-14 22:22:18 +00:00
t.SkipNow()
2019-10-25 15:13:32 +00:00
go notifier.Queue(Mobile)
2018-12-14 10:13:35 +00:00
time.Sleep(15 * time.Second)
2019-10-25 15:13:32 +00:00
assert.Equal(t, MOBILE_ID, Mobile.Var1)
assert.Equal(t, 0, len(Mobile.Queue))
})
}