2016-08-02 07:42:46 +00:00
|
|
|
package buntdb
|
2016-08-02 07:35:28 +00:00
|
|
|
|
|
|
|
import (
|
2016-08-02 08:25:04 +00:00
|
|
|
"os"
|
2016-08-02 07:35:28 +00:00
|
|
|
"testing"
|
2017-01-19 09:08:12 +00:00
|
|
|
|
|
|
|
c "github.com/appleboy/gorush/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-08-02 07:35:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuntDBEngine(t *testing.T) {
|
|
|
|
var val int64
|
|
|
|
|
2017-10-23 03:06:30 +00:00
|
|
|
config, _ := c.LoadConf("")
|
2016-08-02 07:35:28 +00:00
|
|
|
|
2016-08-02 08:25:04 +00:00
|
|
|
if _, err := os.Stat(config.Stat.BuntDB.Path); os.IsNotExist(err) {
|
2017-08-24 03:25:05 +00:00
|
|
|
err := os.RemoveAll(config.Stat.BuntDB.Path)
|
|
|
|
assert.Nil(t, err)
|
2016-08-02 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB := New(config)
|
2017-08-24 03:25:05 +00:00
|
|
|
err := buntDB.Init()
|
|
|
|
assert.Nil(t, err)
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.Reset()
|
2016-08-02 07:35:28 +00:00
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddTotalCount(10)
|
|
|
|
val = buntDB.GetTotalCount()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(10), val)
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddTotalCount(10)
|
|
|
|
val = buntDB.GetTotalCount()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddIosSuccess(20)
|
|
|
|
val = buntDB.GetIosSuccess()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddIosError(30)
|
|
|
|
val = buntDB.GetIosError()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(30), val)
|
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddAndroidSuccess(40)
|
|
|
|
val = buntDB.GetAndroidSuccess()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(40), val)
|
|
|
|
|
2016-08-02 07:42:46 +00:00
|
|
|
buntDB.AddAndroidError(50)
|
|
|
|
val = buntDB.GetAndroidError()
|
2016-08-02 07:35:28 +00:00
|
|
|
assert.Equal(t, int64(50), val)
|
2016-08-02 07:42:46 +00:00
|
|
|
|
|
|
|
buntDB.Reset()
|
|
|
|
val = buntDB.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(0), val)
|
2020-04-23 07:39:24 +00:00
|
|
|
|
|
|
|
assert.NoError(t, buntDB.Close())
|
2016-08-02 07:35:28 +00:00
|
|
|
}
|