2016-05-02 04:06:08 +00:00
|
|
|
package redis
|
|
|
|
|
|
|
|
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 04:06:08 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRedisServerError(t *testing.T) {
|
2017-10-23 03:06:30 +00:00
|
|
|
config, _ := c.LoadConf("")
|
2017-05-04 03:09:07 +00:00
|
|
|
config.Stat.Redis.Addr = "redis:6370"
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis := New(config)
|
|
|
|
err := redis.Init()
|
2016-05-02 04:06:08 +00:00
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRedisEngine(t *testing.T) {
|
|
|
|
var val int64
|
|
|
|
|
2017-10-23 03:06:30 +00:00
|
|
|
config, _ := c.LoadConf("")
|
2017-05-04 03:09:07 +00:00
|
|
|
config.Stat.Redis.Addr = "redis:6379"
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis := New(config)
|
2017-08-24 03:25:05 +00:00
|
|
|
err := redis.Init()
|
|
|
|
assert.Nil(t, err)
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.Reset()
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddTotalCount(10)
|
|
|
|
val = redis.GetTotalCount()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(10), val)
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddTotalCount(10)
|
|
|
|
val = redis.GetTotalCount()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddIosSuccess(20)
|
|
|
|
val = redis.GetIosSuccess()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(20), val)
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddIosError(30)
|
|
|
|
val = redis.GetIosError()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(30), val)
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddAndroidSuccess(40)
|
|
|
|
val = redis.GetAndroidSuccess()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(40), val)
|
2016-05-02 04:06:08 +00:00
|
|
|
|
2016-05-02 11:42:21 +00:00
|
|
|
redis.AddAndroidError(50)
|
|
|
|
val = redis.GetAndroidError()
|
2016-05-02 04:34:35 +00:00
|
|
|
assert.Equal(t, int64(50), val)
|
2016-08-03 06:30:21 +00:00
|
|
|
|
|
|
|
// test reset db
|
|
|
|
redis.Reset()
|
|
|
|
val = redis.GetAndroidError()
|
|
|
|
assert.Equal(t, int64(0), val)
|
2016-05-02 04:06:08 +00:00
|
|
|
}
|