clean up the tub location tests a bit

This commit is contained in:
Jean-Paul Calderone 2020-10-22 14:41:28 -04:00
parent ea257681bb
commit 606617cbfd

View File

@ -89,7 +89,31 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
# conflict with another service to prove it.
self._available_port = 22
def _test_location(self, basedir, expected_addresses, tub_port=None, tub_location=None, local_addresses=None):
def _test_location(
self,
expected_addresses,
tub_port=None,
tub_location=None,
local_addresses=None,
):
"""
Verify that a Tub configured with the given *tub.port* and *tub.location*
values generates fURLs with the given addresses in its location hints.
:param [str] expected_addresses: The addresses which must appear in
the generated fURL for the test to pass. All addresses must
appear.
:param tub_port: If not ``None`` then a value for the *tub.port*
configuration item.
:param tub_location: If not ``None`` then a value for the *tub.port*
configuration item.
:param local_addresses: If not ``None`` then a list of addresses to
supply to the system under test as local addresses.
"""
basedir = self.mktemp()
create_node_dir(basedir, "testing")
config_data = "[node]\n"
if tub_port:
@ -97,12 +121,11 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
if tub_location is not None:
config_data += "tub.location = {}\n".format(tub_location)
if local_addresses:
if local_addresses is not None:
self.patch(iputil, 'get_local_addresses_sync',
lambda: local_addresses)
tub = testing_tub(config_data)
tub.setServiceParent(self.parent)
class Foo(object):
pass
@ -112,19 +135,16 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
self.assertIn(address, furl)
def test_location1(self):
return self._test_location(basedir="test_node/test_location1",
expected_addresses=["192.0.2.0:1234"],
return self._test_location(expected_addresses=["192.0.2.0:1234"],
tub_location="192.0.2.0:1234")
def test_location2(self):
return self._test_location(basedir="test_node/test_location2",
expected_addresses=["192.0.2.0:1234", "example.org:8091"],
return self._test_location(expected_addresses=["192.0.2.0:1234", "example.org:8091"],
tub_location="192.0.2.0:1234,example.org:8091")
def test_location_not_set(self):
"""Checks the autogenerated furl when tub.location is not set."""
return self._test_location(
basedir="test_node/test_location3",
expected_addresses=[
"127.0.0.1:{}".format(self._available_port),
"192.0.2.0:{}".format(self._available_port),
@ -136,7 +156,6 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
def test_location_auto_and_explicit(self):
"""Checks the autogenerated furl when tub.location contains 'AUTO'."""
return self._test_location(
basedir="test_node/test_location4",
expected_addresses=[
"127.0.0.1:{}".format(self._available_port),
"192.0.2.0:{}".format(self._available_port),