|
| 1 | +from unittest import TestCase |
| 2 | +from kazoo.hosts import collect_hosts |
| 3 | + |
| 4 | + |
| 5 | +class HostsTestCase(TestCase): |
| 6 | + |
| 7 | + def test_ipv4(self): |
| 8 | + hosts, chroot = collect_hosts('127.0.0.1:2181, 192.168.1.2:2181, \ |
| 9 | + 132.254.111.10:2181') |
| 10 | + self.assertEquals([('127.0.0.1', 2181), |
| 11 | + ('192.168.1.2', 2181), |
| 12 | + ('132.254.111.10', 2181)], hosts) |
| 13 | + self.assertEquals(None, chroot) |
| 14 | + |
| 15 | + hosts, chroot = collect_hosts(['127.0.0.1:2181', |
| 16 | + '192.168.1.2:2181', |
| 17 | + '132.254.111.10:2181']) |
| 18 | + self.assertEquals([('127.0.0.1', 2181), |
| 19 | + ('192.168.1.2', 2181), |
| 20 | + ('132.254.111.10', 2181)], hosts) |
| 21 | + self.assertEquals(None, chroot) |
| 22 | + |
| 23 | + def test_ipv6(self): |
| 24 | + hosts, chroot = collect_hosts('[fe80::200:5aee:feaa:20a2]:2181') |
| 25 | + self.assertEquals([('fe80::200:5aee:feaa:20a2', 2181)], hosts) |
| 26 | + self.assertEquals(None, chroot) |
| 27 | + |
| 28 | + hosts, chroot = collect_hosts(['[fe80::200:5aee:feaa:20a2]:2181']) |
| 29 | + self.assertEquals([('fe80::200:5aee:feaa:20a2', 2181)], hosts) |
| 30 | + self.assertEquals(None, chroot) |
| 31 | + |
| 32 | + def test_hosts_list(self): |
| 33 | + |
| 34 | + hosts, chroot = collect_hosts('zk01:2181, zk02:2181, zk03:2181') |
| 35 | + expected1 = [('zk01', 2181), ('zk02', 2181), ('zk03', 2181)] |
| 36 | + self.assertEquals(expected1, hosts) |
| 37 | + self.assertEquals(None, chroot) |
| 38 | + |
| 39 | + hosts, chroot = collect_hosts(['zk01:2181', 'zk02:2181', 'zk03:2181']) |
| 40 | + self.assertEquals(expected1, hosts) |
| 41 | + self.assertEquals(None, chroot) |
| 42 | + |
| 43 | + expected2 = '/test' |
| 44 | + hosts, chroot = collect_hosts('zk01:2181, zk02:2181, zk03:2181/test') |
| 45 | + self.assertEquals(expected1, hosts) |
| 46 | + self.assertEquals(expected2, chroot) |
| 47 | + |
| 48 | + hosts, chroot = collect_hosts(['zk01:2181', |
| 49 | + 'zk02:2181', |
| 50 | + 'zk03:2181', '/test']) |
| 51 | + self.assertEquals(expected1, hosts) |
| 52 | + self.assertEquals(expected2, chroot) |
0 commit comments