2021-07-13 15:58:47 +00:00
|
|
|
package status
|
2016-04-15 01:41:10 +00:00
|
|
|
|
|
|
|
import (
|
2021-07-13 15:58:47 +00:00
|
|
|
"log"
|
2016-04-15 01:41:10 +00:00
|
|
|
"testing"
|
2017-01-19 08:56:30 +00:00
|
|
|
"time"
|
2016-12-20 01:34:25 +00:00
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
"github.com/appleboy/gorush/config"
|
|
|
|
"github.com/appleboy/gorush/logx"
|
|
|
|
|
2016-12-20 01:34:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-04-15 01:41:10 +00:00
|
|
|
)
|
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
PushConf, _ := config.LoadConf("")
|
|
|
|
if err := logx.InitLog(
|
|
|
|
PushConf.Log.AccessLevel,
|
|
|
|
PushConf.Log.AccessLog,
|
|
|
|
PushConf.Log.ErrorLevel,
|
|
|
|
PushConf.Log.ErrorLog,
|
|
|
|
); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Run()
|
|
|
|
}
|
|
|
|
|
2016-12-20 01:34:25 +00:00
|
|
|
func TestStorageDriverExist(t *testing.T) {
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-12-20 01:34:25 +00:00
|
|
|
PushConf.Stat.Engine = "Test"
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
2016-12-20 01:34:25 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
2016-05-02 09:03:08 +00:00
|
|
|
func TestStatForMemoryEngine(t *testing.T) {
|
2017-01-19 08:56:30 +00:00
|
|
|
// wait android push notification response.
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
2016-04-22 09:54:00 +00:00
|
|
|
var val int64
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-05-02 09:03:08 +00:00
|
|
|
PushConf.Stat.Engine = "memory"
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
2017-08-24 02:46:00 +00:00
|
|
|
assert.Nil(t, err)
|
2016-04-22 09:54:00 +00:00
|
|
|
|
2016-05-02 09:03:08 +00:00
|
|
|
StatStorage.AddTotalCount(100)
|
|
|
|
StatStorage.AddIosSuccess(200)
|
|
|
|
StatStorage.AddIosError(300)
|
|
|
|
StatStorage.AddAndroidSuccess(400)
|
|
|
|
StatStorage.AddAndroidError(500)
|
2016-04-23 07:13:57 +00:00
|
|
|
|
2016-05-02 09:03:08 +00:00
|
|
|
val = StatStorage.GetTotalCount()
|
2016-04-23 07:13:57 +00:00
|
|
|
assert.Equal(t, int64(100), val)
|
2016-05-02 09:03:08 +00:00
|
|
|
val = StatStorage.GetIosSuccess()
|
2016-04-23 07:13:57 +00:00
|
|
|
assert.Equal(t, int64(200), val)
|
2016-05-02 09:03:08 +00:00
|
|
|
val = StatStorage.GetIosError()
|
2016-04-23 07:13:57 +00:00
|
|
|
assert.Equal(t, int64(300), val)
|
2016-05-02 09:03:08 +00:00
|
|
|
val = StatStorage.GetAndroidSuccess()
|
2016-04-23 07:13:57 +00:00
|
|
|
assert.Equal(t, int64(400), val)
|
2016-05-02 09:03:08 +00:00
|
|
|
val = StatStorage.GetAndroidError()
|
2016-04-23 07:13:57 +00:00
|
|
|
assert.Equal(t, int64(500), val)
|
2016-04-22 09:54:00 +00:00
|
|
|
}
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
func TestRedisServerSuccess(t *testing.T) {
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-05-02 12:22:37 +00:00
|
|
|
PushConf.Stat.Engine = "redis"
|
2017-05-04 03:09:07 +00:00
|
|
|
PushConf.Stat.Redis.Addr = "redis:6379"
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
func TestRedisServerError(t *testing.T) {
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-05-02 12:22:37 +00:00
|
|
|
PushConf.Stat.Engine = "redis"
|
2017-05-04 03:09:07 +00:00
|
|
|
PushConf.Stat.Redis.Addr = "redis:6370"
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
func TestStatForRedisEngine(t *testing.T) {
|
|
|
|
var val int64
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-05-02 11:42:21 +00:00
|
|
|
PushConf.Stat.Engine = "redis"
|
2017-05-04 03:09:07 +00:00
|
|
|
PushConf.Stat.Redis.Addr = "redis:6379"
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
2017-08-24 02:46:00 +00:00
|
|
|
assert.Nil(t, err)
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
StatStorage.Init()
|
|
|
|
StatStorage.Reset()
|
|
|
|
|
|
|
|
StatStorage.AddTotalCount(100)
|
|
|
|
StatStorage.AddIosSuccess(200)
|
|
|
|
StatStorage.AddIosError(300)
|
|
|
|
StatStorage.AddAndroidSuccess(400)
|
|
|
|
StatStorage.AddAndroidError(500)
|
|
|
|
|
|
|
|
val = StatStorage.GetTotalCount()
|
|
|
|
assert.Equal(t, int64(100), val)
|
|
|
|
val = StatStorage.GetIosSuccess()
|
|
|
|
assert.Equal(t, int64(200), val)
|
|
|
|
val = StatStorage.GetIosError()
|
|
|
|
assert.Equal(t, int64(300), val)
|
|
|
|
val = StatStorage.GetAndroidSuccess()
|
|
|
|
assert.Equal(t, int64(400), val)
|
|
|
|
val = StatStorage.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(500), val)
|
|
|
|
}
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
func TestDefaultEngine(t *testing.T) {
|
|
|
|
var val int64
|
2016-12-20 01:34:25 +00:00
|
|
|
// defaul engine as memory
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
|
|
|
err := InitAppStatus(PushConf)
|
2017-08-24 02:46:00 +00:00
|
|
|
assert.Nil(t, err)
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-12-20 01:34:25 +00:00
|
|
|
StatStorage.Reset()
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
StatStorage.AddTotalCount(100)
|
|
|
|
StatStorage.AddIosSuccess(200)
|
|
|
|
StatStorage.AddIosError(300)
|
|
|
|
StatStorage.AddAndroidSuccess(400)
|
|
|
|
StatStorage.AddAndroidError(500)
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
val = StatStorage.GetTotalCount()
|
|
|
|
assert.Equal(t, int64(100), val)
|
|
|
|
val = StatStorage.GetIosSuccess()
|
|
|
|
assert.Equal(t, int64(200), val)
|
|
|
|
val = StatStorage.GetIosError()
|
|
|
|
assert.Equal(t, int64(300), val)
|
|
|
|
val = StatStorage.GetAndroidSuccess()
|
|
|
|
assert.Equal(t, int64(400), val)
|
|
|
|
val = StatStorage.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(500), val)
|
|
|
|
}
|
2016-05-02 09:03:08 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
func TestStatForBoltDBEngine(t *testing.T) {
|
|
|
|
var val int64
|
2021-07-13 15:58:47 +00:00
|
|
|
PushConf, _ := config.LoadConf("")
|
2016-05-02 12:22:37 +00:00
|
|
|
PushConf.Stat.Engine = "boltdb"
|
2021-07-13 15:58:47 +00:00
|
|
|
err := InitAppStatus(PushConf)
|
|
|
|
assert.Nil(t, err)
|
2016-05-02 12:22:37 +00:00
|
|
|
|
|
|
|
StatStorage.Reset()
|
|
|
|
|
|
|
|
StatStorage.AddTotalCount(100)
|
|
|
|
StatStorage.AddIosSuccess(200)
|
|
|
|
StatStorage.AddIosError(300)
|
|
|
|
StatStorage.AddAndroidSuccess(400)
|
|
|
|
StatStorage.AddAndroidError(500)
|
|
|
|
|
|
|
|
val = StatStorage.GetTotalCount()
|
|
|
|
assert.Equal(t, int64(100), val)
|
|
|
|
val = StatStorage.GetIosSuccess()
|
|
|
|
assert.Equal(t, int64(200), val)
|
|
|
|
val = StatStorage.GetIosError()
|
|
|
|
assert.Equal(t, int64(300), val)
|
|
|
|
val = StatStorage.GetAndroidSuccess()
|
|
|
|
assert.Equal(t, int64(400), val)
|
|
|
|
val = StatStorage.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(500), val)
|
|
|
|
}
|
2016-09-19 13:52:40 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// func TestStatForBuntDBEngine(t *testing.T) {
|
|
|
|
// var val int64
|
|
|
|
// PushConf.Stat.Engine = "buntdb"
|
|
|
|
// err := InitAppStatus()
|
|
|
|
// assert.Nil(t, err)
|
2016-09-19 13:52:40 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// StatStorage.Reset()
|
2016-09-19 13:52:40 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// StatStorage.AddTotalCount(100)
|
|
|
|
// StatStorage.AddIosSuccess(200)
|
|
|
|
// StatStorage.AddIosError(300)
|
|
|
|
// StatStorage.AddAndroidSuccess(400)
|
|
|
|
// StatStorage.AddAndroidError(500)
|
2016-09-19 13:52:40 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// val = StatStorage.GetTotalCount()
|
|
|
|
// assert.Equal(t, int64(100), val)
|
|
|
|
// val = StatStorage.GetIosSuccess()
|
|
|
|
// assert.Equal(t, int64(200), val)
|
|
|
|
// val = StatStorage.GetIosError()
|
|
|
|
// assert.Equal(t, int64(300), val)
|
|
|
|
// val = StatStorage.GetAndroidSuccess()
|
|
|
|
// assert.Equal(t, int64(400), val)
|
|
|
|
// val = StatStorage.GetAndroidError()
|
|
|
|
// assert.Equal(t, int64(500), val)
|
|
|
|
// }
|
2016-09-19 13:52:40 +00:00
|
|
|
|
|
|
|
// func TestStatForLevelDBEngine(t *testing.T) {
|
|
|
|
// var val int64
|
|
|
|
// PushConf.Stat.Engine = "leveldb"
|
2019-03-16 03:37:01 +00:00
|
|
|
// err := InitAppStatus()
|
|
|
|
// assert.Nil(t, err)
|
2016-09-19 13:52:40 +00:00
|
|
|
|
|
|
|
// StatStorage.Reset()
|
|
|
|
|
|
|
|
// StatStorage.AddTotalCount(100)
|
|
|
|
// StatStorage.AddIosSuccess(200)
|
|
|
|
// StatStorage.AddIosError(300)
|
|
|
|
// StatStorage.AddAndroidSuccess(400)
|
|
|
|
// StatStorage.AddAndroidError(500)
|
|
|
|
|
|
|
|
// val = StatStorage.GetTotalCount()
|
|
|
|
// assert.Equal(t, int64(100), val)
|
|
|
|
// val = StatStorage.GetIosSuccess()
|
|
|
|
// assert.Equal(t, int64(200), val)
|
|
|
|
// val = StatStorage.GetIosError()
|
|
|
|
// assert.Equal(t, int64(300), val)
|
|
|
|
// val = StatStorage.GetAndroidSuccess()
|
|
|
|
// assert.Equal(t, int64(400), val)
|
|
|
|
// val = StatStorage.GetAndroidError()
|
|
|
|
// assert.Equal(t, int64(500), val)
|
|
|
|
// }
|
2018-04-16 09:26:15 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// func TestStatForBadgerEngine(t *testing.T) {
|
|
|
|
// var val int64
|
|
|
|
// PushConf.Stat.Engine = "badger"
|
|
|
|
// err := InitAppStatus()
|
|
|
|
// assert.Nil(t, err)
|
2018-04-16 09:26:15 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// StatStorage.Reset()
|
2018-04-16 09:26:15 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// StatStorage.AddTotalCount(100)
|
|
|
|
// StatStorage.AddIosSuccess(200)
|
|
|
|
// StatStorage.AddIosError(300)
|
|
|
|
// StatStorage.AddAndroidSuccess(400)
|
|
|
|
// StatStorage.AddAndroidError(500)
|
2018-04-16 09:26:15 +00:00
|
|
|
|
2019-03-16 03:37:01 +00:00
|
|
|
// val = StatStorage.GetTotalCount()
|
|
|
|
// assert.Equal(t, int64(100), val)
|
|
|
|
// val = StatStorage.GetIosSuccess()
|
|
|
|
// assert.Equal(t, int64(200), val)
|
|
|
|
// val = StatStorage.GetIosError()
|
|
|
|
// assert.Equal(t, int64(300), val)
|
|
|
|
// val = StatStorage.GetAndroidSuccess()
|
|
|
|
// assert.Equal(t, int64(400), val)
|
|
|
|
// val = StatStorage.GetAndroidError()
|
|
|
|
// assert.Equal(t, int64(500), val)
|
|
|
|
// }
|