forked from bigdatacesga/service-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
67 lines (50 loc) · 2.23 KB
/
tests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Tests for the service discovery API"""
import unittest
import consul
class consulTestCase(unittest.TestCase):
def setUp(self):
self.service = consul.Client()
def tearDown(self):
pass
def test_register_new_service(self):
service_name = 'unittest'
service_id = 'unittest1'
service_address = '9.9.9.9'
self.service.register(id=service_id, name=service_name, address=service_address)
returned = self.service.info(name=service_name)
# Clean up
self.service.deregister(service_id)
self.assertEqual(returned[0]['ServiceID'], service_id)
self.assertEqual(returned[0]['ServiceName'], service_name)
self.assertEqual(returned[0]['ServiceAddress'], service_address)
def test_deregister_service(self):
service_name = 'unittest'
service_id = 'unittest1'
service_address = '9.9.9.9'
self.service.register(id=service_id, name=service_name, address=service_address)
returned = self.service.deregister(service_id)
self.assertEqual(returned.status_code, 200)
def test_deregister_nonexistent_service(self):
service_id = 'non_existing_service'
returned = self.service.deregister(service_id)
# In consul deregistering a nonexistent service also returns exit status 200
self.assertEqual(returned.status_code, 200)
def test_list_services(self):
returned = self.service.list()
self.assertTrue(isinstance(returned, dict))
def test_info_service(self):
service_name = 'unittest-info'
service_id = 'unittest1'
service_address = '9.9.9.9'
self.service.register(id=service_id, name=service_name, address=service_address)
returned = self.service.info(name=service_name)
# Clean up
self.service.deregister(service_id)
self.assertEqual(returned[0]['ServiceID'], service_id)
self.assertEqual(returned[0]['ServiceName'], service_name)
self.assertEqual(returned[0]['ServiceAddress'], service_address)
def test_info_nonexistent_service(self):
returned = self.service.info(name='nonexistent_service_ABC')
self.assertEqual(returned, [])
if __name__ == '__main__':
unittest.main()