refactor default engine as memory.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
af1d4aecc2
commit
9595062bbf
|
@ -1,6 +1,9 @@
|
|||
package gorush
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/appleboy/gorush/storage/boltdb"
|
||||
"github.com/appleboy/gorush/storage/buntdb"
|
||||
"github.com/appleboy/gorush/storage/leveldb"
|
||||
|
@ -8,7 +11,6 @@ import (
|
|||
"github.com/appleboy/gorush/storage/redis"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/thoas/stats"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Stats provide response time, status code count, etc.
|
||||
|
@ -50,12 +52,14 @@ func InitAppStatus() error {
|
|||
case "leveldb":
|
||||
StatStorage = leveldb.New(PushConf)
|
||||
default:
|
||||
StatStorage = memory.New()
|
||||
err := errors.New("can't find storage driver")
|
||||
if err != nil {
|
||||
LogError.Error("storage error: " + err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := StatStorage.Init()
|
||||
|
||||
if err != nil {
|
||||
if err := StatStorage.Init(); err != nil {
|
||||
LogError.Error("storage error: " + err.Error())
|
||||
|
||||
return err
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
package gorush
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStorageDriverExist(t *testing.T) {
|
||||
PushConf.Stat.Engine = "Test"
|
||||
err := InitAppStatus()
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestStatForMemoryEngine(t *testing.T) {
|
||||
var val int64
|
||||
PushConf.Stat.Engine = "memory"
|
||||
|
@ -75,9 +82,11 @@ func TestStatForRedisEngine(t *testing.T) {
|
|||
|
||||
func TestDefaultEngine(t *testing.T) {
|
||||
var val int64
|
||||
PushConf.Stat.Engine = "test"
|
||||
// defaul engine as memory
|
||||
InitAppStatus()
|
||||
|
||||
StatStorage.Reset()
|
||||
|
||||
StatStorage.AddTotalCount(100)
|
||||
StatStorage.AddIosSuccess(200)
|
||||
StatStorage.AddIosError(300)
|
||||
|
|
Loading…
Reference in New Issue