2014-05-16 11:03:23 +04:00
|
|
|
package server
|
2014-05-02 13:08:20 +04:00
|
|
|
|
|
|
|
import (
|
2015-03-03 05:18:54 +03:00
|
|
|
"github.com/siddontang/ledisdb/client/goledis"
|
2014-08-07 12:49:48 +04:00
|
|
|
"github.com/siddontang/ledisdb/config"
|
2014-05-05 07:37:44 +04:00
|
|
|
"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
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
var testLedisClient *ledis.Client
|
2014-05-05 07:37:44 +04:00
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
func newTestLedisClient() {
|
|
|
|
cfg := new(ledis.Config)
|
|
|
|
cfg.Addr = "127.0.0.1:16380"
|
|
|
|
cfg.MaxIdleConns = 4
|
|
|
|
testLedisClient = ledis.NewClient(cfg)
|
2014-05-05 07:37:44 +04:00
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
func getTestConn() *ledis.Conn {
|
2014-05-16 05:10:09 +04:00
|
|
|
startTestApp()
|
2015-03-02 12:12:55 +03:00
|
|
|
conn, _ := testLedisClient.Get()
|
|
|
|
return conn
|
2014-05-05 07:37:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func startTestApp() {
|
|
|
|
f := func() {
|
2014-06-22 06:39:23 +04:00
|
|
|
newTestLedisClient()
|
2014-05-02 13:08:20 +04:00
|
|
|
|
2014-10-11 12:00:59 +04:00
|
|
|
cfg := config.NewConfigDefault()
|
2014-08-07 12:49:48 +04:00
|
|
|
cfg.DataDir = "/tmp/testdb"
|
|
|
|
os.RemoveAll(cfg.DataDir)
|
2014-05-05 07:37:44 +04:00
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
cfg.Addr = "127.0.0.1:16380"
|
2014-12-26 05:08:37 +03:00
|
|
|
cfg.HttpAddr = "127.0.0.1:21181"
|
2014-05-05 07:37:44 +04:00
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
os.RemoveAll("/tmp/testdb")
|
2014-05-05 07:37:44 +04:00
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
var err error
|
2014-05-05 07:37:44 +04:00
|
|
|
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
|
|
|
}
|