This repository was archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathtest_base.py
More file actions
74 lines (57 loc) · 2.16 KB
/
test_base.py
File metadata and controls
74 lines (57 loc) · 2.16 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import collections
import consul.base
Request = collections.namedtuple(
'Request', ['method', 'path', 'params', 'data'])
class HTTPClient(object):
def __init__(self, host=None, port=None, scheme=None, verify=True):
pass
def get(self, callback, path, params=None):
return Request('get', path, params, None)
def put(self, callback, path, params=None, data=''):
return Request('put', path, params, data)
def delete(self, callback, path, params=None):
return Request('delete', path, params, None)
class Consul(consul.base.Consul):
def connect(self, host, port, scheme, verify=True):
return HTTPClient(host, port, scheme, verify=verify)
def _should_support(c):
return (
# kv
lambda **kw: c.kv.get('foo', **kw),
# catalog
c.catalog.nodes,
c.catalog.services,
lambda **kw: c.catalog.node('foo', **kw),
lambda **kw: c.catalog.service('foo', **kw),
# session
c.session.list,
lambda **kw: c.session.info('foo', **kw),
lambda **kw: c.session.node('foo', **kw),
)
class TestIndex(object):
"""
Tests read requests that should support blocking on an index
"""
def test_index(self):
c = Consul()
for r in _should_support(c):
assert r().params == {}
assert r(index='5').params == {'index': '5'}
class TestConsistency(object):
"""
Tests read requests that should support consistency modes
"""
def test_explict(self):
c = Consul()
for r in _should_support(c):
assert r().params == {}
assert r(consistency='default').params == {}
assert r(consistency='consistent').params == {'consistent': '1'}
assert r(consistency='stale').params == {'stale': '1'}
def test_implicit(self):
c = Consul(consistency='consistent')
for r in _should_support(c):
assert r().params == {'consistent': '1'}
assert r(consistency='default').params == {}
assert r(consistency='consistent').params == {'consistent': '1'}
assert r(consistency='stale').params == {'stale': '1'}