-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrediser_test.py
46 lines (40 loc) · 1.45 KB
/
rediser_test.py
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
#!/usr/bin/env python
import argparse
from rediser import tprint, Client, ClusterClient
def test_client(host='127.0.0.1', port=1279):
cases = [
[('set', 'hello', 'world'), 'OK'],
[('get', 'hello'), 'world'],
]
tprint('---------------test client----------------')
c = Client(host=host, port=port)
for case in cases:
r = c.call(*case[0])
if r == case[1]:
tprint('PASS', '%s:%s' % (repr(case[0]), repr(r)))
else:
tprint('FAIL', '%s:%s != %s' % (repr(case[0]), repr(r), repr(case[1])))
def test_cluster_client(addrs=['192.168.2.107:2211']):
cases = [
[('set', 'hello', 'world'), 'OK'],
[('get', 'hello'), 'world'],
]
tprint('---------------test cluster client----------------')
c = ClusterClient(addrs)
for case in cases:
r = c.call(*case[0])
if r == case[1]:
tprint('PASS', '%s:%s' % (repr(case[0]), repr(r)))
else:
tprint('FAIL', '%s:%s != %s' % (repr(case[0]), repr(r), repr(case[1])))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('cmd', nargs='?', choices=['all', 'client', 'clusterclient'], default='all', help='specify test command')
args = parser.parse_args()
if args.cmd == 'client':
test_client()
elif args.cmd == 'clusterclient':
test_cluster_client()
elif args.cmd == 'all':
test_client()
test_cluster_client()