2018-04-16 09:26:15 +00:00
|
|
|
package badger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-16 04:10:34 +00:00
|
|
|
"github.com/appleboy/gorush/config"
|
2018-04-16 09:26:15 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBadgerEngine(t *testing.T) {
|
|
|
|
var val int64
|
|
|
|
|
2021-07-16 04:10:34 +00:00
|
|
|
cfg, _ := config.LoadConf()
|
2018-04-16 09:26:15 +00:00
|
|
|
|
2021-07-16 04:10:34 +00:00
|
|
|
badger := New(cfg)
|
2018-04-16 09:26:15 +00:00
|
|
|
err := badger.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
badger.Reset()
|
|
|
|
|
|
|
|
badger.AddTotalCount(10)
|
|
|
|
val = badger.GetTotalCount()
|
|
|
|
assert.Equal(t, int64(10), val)
|
|
|
|
badger.AddTotalCount(10)
|
|
|
|
val = badger.GetTotalCount()
|
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
|
|
|
badger.AddIosSuccess(20)
|
|
|
|
val = badger.GetIosSuccess()
|
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
|
|
|
badger.AddIosError(30)
|
|
|
|
val = badger.GetIosError()
|
|
|
|
assert.Equal(t, int64(30), val)
|
|
|
|
|
|
|
|
badger.AddAndroidSuccess(40)
|
|
|
|
val = badger.GetAndroidSuccess()
|
|
|
|
assert.Equal(t, int64(40), val)
|
|
|
|
|
|
|
|
badger.AddAndroidError(50)
|
|
|
|
val = badger.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(50), val)
|
|
|
|
|
|
|
|
// test reset db
|
|
|
|
badger.Reset()
|
|
|
|
val = badger.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(0), val)
|
2020-04-23 07:39:24 +00:00
|
|
|
|
|
|
|
assert.NoError(t, badger.Close())
|
2018-04-16 09:26:15 +00:00
|
|
|
}
|