49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package redis
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
"github.com/astaxie/beego"
|
|
)
|
|
|
|
func init() {
|
|
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
|
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
|
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
|
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
|
|
globals.Init()
|
|
beegodb.Init()
|
|
api.Init()
|
|
}
|
|
|
|
type FuckYou struct {
|
|
Key string `json:"key"`
|
|
}
|
|
|
|
func TestIt(t *testing.T) {
|
|
cacher := New("localhost", 6379, "")
|
|
cacher.FlushAll()
|
|
if cacher.Get("key") != nil {
|
|
t.Fatal("should get nothing")
|
|
}
|
|
if err := cacher.Set("key", map[string]interface{}{
|
|
"key": "value",
|
|
}, 0); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if cacher.Get("key") == nil {
|
|
t.Fatal("should not get nothing")
|
|
}
|
|
|
|
result := new(FuckYou)
|
|
cacher.GetAs("key", result)
|
|
if result.Key != "value" {
|
|
t.Fatal("should get value")
|
|
}
|
|
}
|