2016-05-02 06:52:38 +00:00
|
|
|
package boltdb
|
|
|
|
|
|
|
|
import (
|
2017-01-19 09:08:12 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-05-03 01:56:59 +00:00
|
|
|
c "github.com/appleboy/gorush/config"
|
2016-05-02 06:52:38 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2016-08-03 06:30:21 +00:00
|
|
|
func TestBoltDBEngine(t *testing.T) {
|
2016-05-02 06:52:38 +00:00
|
|
|
var val int64
|
|
|
|
|
2017-10-23 03:06:30 +00:00
|
|
|
config, _ := c.LoadConf("")
|
2016-05-02 06:52:38 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB := New(config)
|
2017-08-24 03:25:05 +00:00
|
|
|
err := boltDB.Init()
|
|
|
|
assert.Nil(t, err)
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.Reset()
|
2016-05-02 06:52:38 +00:00
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddTotalCount(10)
|
|
|
|
val = boltDB.GetTotalCount()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(10), val)
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddTotalCount(10)
|
|
|
|
val = boltDB.GetTotalCount()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddIosSuccess(20)
|
|
|
|
val = boltDB.GetIosSuccess()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddIosError(30)
|
|
|
|
val = boltDB.GetIosError()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(30), val)
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddAndroidSuccess(40)
|
|
|
|
val = boltDB.GetAndroidSuccess()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(40), val)
|
|
|
|
|
2016-05-02 12:22:37 +00:00
|
|
|
boltDB.AddAndroidError(50)
|
|
|
|
val = boltDB.GetAndroidError()
|
2016-05-02 06:52:38 +00:00
|
|
|
assert.Equal(t, int64(50), val)
|
2016-08-03 06:30:21 +00:00
|
|
|
|
|
|
|
// test reset db
|
|
|
|
boltDB.Reset()
|
|
|
|
val = boltDB.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(0), val)
|
2016-05-02 06:52:38 +00:00
|
|
|
}
|