def test_get_instances_all_dc(self): """Test getting instances from ALL known datacenters.""" adapter = ConsulServiceAdapter(dc_aware=False) instances = adapter._fetch_instances('dummy') ips = [instance['ServiceAddress'] for instance in instances] ips.sort() self.assertListEqual(ips, ['127.0.0.1', '127.0.1.1'])
def test_get_notexisting_service(self): adapter = ConsulServiceAdapter(dc_aware=False) with self.assertRaises(NoSuchService): adapter.get_connection('service://notex')
def test_get_connection_single_host(self): adapter = ConsulServiceAdapter() conn = adapter.get_connection('service://dummy/') self.assertEqual(conn.host, '127.0.0.1') self.assertEqual(conn.port, 111)
def test_get_instances(self, dc, required_ip): """Test fetching instances for a given data center. Used DC: {0}""" adapter = ConsulServiceAdapter(dc=dc) instances = adapter._fetch_instances('dummy') first_instance_ip = instances[0]['ServiceAddress'] self.assertEqual(first_instance_ip, required_ip)
def test_get_consul_exception(self): adapter = ConsulServiceAdapter(dc='dummy_dc') with self.assertRaises(ConsulRequestException): adapter.get_connection('service://notex2')