gorush/gorush/status_test.go

123 lines
3.0 KiB
Go

package gorush
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestStatForMemoryEngine(t *testing.T) {
var val int64
PushConf.Stat.Engine = "memory"
InitAppStatus()
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)
}
func TestRedisServerSuccess(t *testing.T) {
PushConf.Stat.Engine = "redis"
PushConf.Stat.Redis.Addr = "localhost:6379"
err := InitAppStatus()
assert.NoError(t, err)
}
func TestRedisServerError(t *testing.T) {
PushConf.Stat.Engine = "redis"
PushConf.Stat.Redis.Addr = "localhost:6370"
err := InitAppStatus()
assert.Error(t, err)
}
func TestStatForRedisEngine(t *testing.T) {
var val int64
PushConf.Stat.Engine = "redis"
PushConf.Stat.Redis.Addr = "localhost:6379"
InitAppStatus()
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)
}
func TestDefaultEngine(t *testing.T) {
var val int64
PushConf.Stat.Engine = "test"
InitAppStatus()
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)
}
func TestStatForBoltDBEngine(t *testing.T) {
var val int64
PushConf.Stat.Engine = "boltdb"
InitAppStatus()
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)
}