ledisdb/server/http/base_test.go

41 lines
731 B
Go
Raw Normal View History

2014-07-23 07:02:10 +04:00
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
2014-07-25 11:18:39 +04:00
if _, err = os.Stat("/tmp/test_http_api_db"); err == nil {
if err = os.RemoveAll("/tmp/test_http_api_db"); err != nil {
2014-07-23 07:02:10 +04:00
panic(err)
}
2014-07-25 11:18:39 +04:00
} else if !os.IsNotExist(err) {
2014-07-23 07:02:10 +04:00
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
}