/
context.go
53 lines (44 loc) 路 1.1 KB
/
context.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
52
53
package redisctx
import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/ovh/venom"
)
// Name is Context Type name.
const Name = "redis"
//Client represents interface of redis client used by venom
type Client interface {
Close() error
Do(commandName string, args ...interface{}) (reply interface{}, err error)
}
// New returns a new TestCaseContext.
func New() venom.TestCaseContext {
ctx := &RedisTestCaseContext{}
ctx.Name = Name
return ctx
}
// RedisTestCaseContext represents the context of a testcase.
type RedisTestCaseContext struct {
venom.CommonTestCaseContext
Client Client
}
// Init Initialize the context.
func (tcc *RedisTestCaseContext) Init() error {
var dialURL string
if v, found := tcc.TestCase.Context["dialURL"]; found {
if url, ok := v.(string); ok {
dialURL = url
} else {
return fmt.Errorf("DialURL property must be a string")
}
} else {
return fmt.Errorf("DialURL property isn't present")
}
var err error
tcc.Client, err = redis.DialURL(dialURL)
return err
}
// Close the context.
func (tcc *RedisTestCaseContext) Close() error {
return tcc.Client.Close()
}