forked from distributedio/titan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_test.go
51 lines (43 loc) · 976 Bytes
/
test_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package command
import (
"bytes"
"io"
"strings"
"github.com/meitu/titan/conf"
"github.com/meitu/titan/context"
"github.com/meitu/titan/db"
)
var cfg = &conf.MockConf().Tikv
var mockdb *db.RedisStore
func init() {
mockdb, _ = db.Open(cfg)
}
func ContextTest(name string, args ...string) *Context {
cliCtx := &context.ClientContext{
DB: mockdb.DB("defalut", 1),
}
servCtx := &context.ServerContext{
RequirePass: "",
Store: mockdb,
}
rootCtx, _ := context.WithCancel(context.New(cliCtx, servCtx))
return &Context{
Name: name,
Args: args,
In: &bytes.Buffer{},
Out: &bytes.Buffer{},
Context: rootCtx,
}
}
func CallTest(name string, args ...string) *bytes.Buffer {
ctx := ContextTest(name, args...)
Call(ctx)
return ctx.Out.(*bytes.Buffer)
}
func ctxString(buf io.Writer) string {
return buf.(*bytes.Buffer).String()
}
func ctxLines(buf io.Writer) []string {
str := ctxString(buf)
return strings.Split(str, "\r\n")
}