This commit is contained in:
wenyekui 2014-07-23 11:02:10 +08:00
parent 1dd7d22198
commit f647c3d815
1 changed files with 40 additions and 0 deletions

40
server/http/base_test.go Normal file
View File

@ -0,0 +1,40 @@
package http
import (
"github.com/siddontang/ledisdb/ledis"
"os"
"sync"
)
var once sync.Once
var ldb *ledis.Ledis
func getTestDB() *ledis.DB {
f := func() {
var err error
if _, err := os.Stat("/tmp/test_http_api_db"); err == nil {
if err := os.RemoveAll("/tmp/test_http_api_db"); err != nil {
panic(err)
}
} else if err != os.ErrNotExist {
panic(err)
}
var cfg ledis.Config
cfg.DataDir = "/tmp/test_http_api_db"
cfg.DataDB.BlockSize = 32768
cfg.DataDB.WriteBufferSize = 20971520
cfg.DataDB.CacheSize = 20971520
cfg.DataDB.Compression = true
ldb, err = ledis.Open(&cfg)
if err != nil {
panic(err)
}
}
once.Do(f)
db, err := ldb.Select(0)
if err != nil {
panic(err)
}
return db
}