ledisdb/ledis/app_test.go

73 lines
1.2 KiB
Go
Raw Normal View History

2014-05-09 10:49:22 +04:00
package ledis
2014-05-02 13:08:20 +04:00
import (
2014-05-05 07:37:44 +04:00
"github.com/garyburd/redigo/redis"
"os"
"sync"
2014-05-02 13:08:20 +04:00
"testing"
)
2014-05-05 07:37:44 +04:00
var testAppOnce sync.Once
var testApp *App
var testPool *redis.Pool
func newTestRedisPool() {
f := func() (redis.Conn, error) {
2014-05-13 04:49:20 +04:00
c, err := redis.Dial("tcp", "127.0.0.1:16380")
2014-05-05 07:37:44 +04:00
if err != nil {
return nil, err
}
return c, nil
}
testPool = redis.NewPool(f, 4)
}
func getTestConn() redis.Conn {
return testPool.Get()
}
func startTestApp() {
f := func() {
newTestRedisPool()
2014-05-02 13:08:20 +04:00
2014-05-08 06:54:33 +04:00
os.RemoveAll("/tmp/testdb")
2014-05-05 07:37:44 +04:00
var d = []byte(`
{
2014-05-13 04:49:20 +04:00
"addr" : "127.0.0.1:16380",
2014-05-05 07:37:44 +04:00
"leveldb" :
{
2014-05-08 06:54:33 +04:00
"path" : "/tmp/testdb",
2014-05-05 07:37:44 +04:00
"compression":true,
"block_size" : 32768,
"write_buffer_size" : 2097152,
"cache_size" : 20971520
}
}
`)
cfg, err := NewConfig(d)
if err != nil {
println(err.Error())
panic(err)
}
testApp, err = NewApp(cfg)
if err != nil {
println(err.Error())
panic(err)
}
go testApp.Run()
}
testAppOnce.Do(f)
}
func TestApp(t *testing.T) {
startTestApp()
2014-05-02 13:08:20 +04:00
}