mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 13:07:56 +00:00
Make merge_config
fail on overlapping configs
This isn't expected to happen. If it does it would be nice to see it instead of silently continue working with some config dropped on the floor.
This commit is contained in:
parent
da43acf52e
commit
02a696d73b
@ -273,9 +273,16 @@ def merge_config(
|
||||
|
||||
If either is ``None`` then the result is ``None``. This supports the
|
||||
"disable listeners" functionality.
|
||||
|
||||
:raise ValueError: If the keys in the node configs overlap.
|
||||
"""
|
||||
if left is None or right is None:
|
||||
return None
|
||||
|
||||
overlap = set(left.node_config) & set(right.node_config)
|
||||
if overlap:
|
||||
raise ValueError(f"Node configs overlap: {overlap}")
|
||||
|
||||
return ListenerConfig(
|
||||
list(left.tub_ports) + list(right.tub_ports),
|
||||
list(left.tub_locations) + list(right.tub_locations),
|
||||
|
@ -25,6 +25,60 @@ def read_config(basedir):
|
||||
config = configutil.get_config(tahoe_cfg)
|
||||
return config
|
||||
|
||||
class MergeConfigTests(unittest.TestCase):
|
||||
"""
|
||||
Tests for ``create_node.merge_config``.
|
||||
"""
|
||||
def test_disable_left(self) -> None:
|
||||
"""
|
||||
If the left argument to ``create_node.merge_config`` is ``None``
|
||||
then the return value is ``None``.
|
||||
"""
|
||||
conf = ListenerConfig([], [], {})
|
||||
self.assertEqual(None, create_node.merge_config(None, conf))
|
||||
|
||||
def test_disable_right(self) -> None:
|
||||
"""
|
||||
If the right argument to ``create_node.merge_config`` is ``None``
|
||||
then the return value is ``None``.
|
||||
"""
|
||||
conf = ListenerConfig([], [], {})
|
||||
self.assertEqual(None, create_node.merge_config(conf, None))
|
||||
|
||||
def test_disable_both(self) -> None:
|
||||
"""
|
||||
If both arguments to ``create_node.merge_config`` are ``None``
|
||||
then the return value is ``None``.
|
||||
"""
|
||||
self.assertEqual(None, create_node.merge_config(None, None))
|
||||
|
||||
def test_overlapping_keys(self) -> None:
|
||||
"""
|
||||
If there are any keys in the ``node_config`` of the left and right
|
||||
parameters that are shared then ``ValueError`` is raised.
|
||||
"""
|
||||
left = ListenerConfig([], [], {"foo": "bar"})
|
||||
right = ListenerConfig([], [], {"foo": "baz"})
|
||||
self.assertRaises(ValueError, lambda: create_node.merge_config(left, right))
|
||||
|
||||
def test_merge(self) -> None:
|
||||
"""
|
||||
``create_node.merge_config`` returns a ``ListenerConfig`` that has
|
||||
all of the ports, locations, and node config from each of the two
|
||||
``ListenerConfig`` values given.
|
||||
"""
|
||||
left = ListenerConfig(["left-port"], ["left-location"], {"left": "foo"})
|
||||
right = ListenerConfig(["right-port"], ["right-location"], {"right": "bar"})
|
||||
result = create_node.merge_config(left, right)
|
||||
self.assertEqual(
|
||||
ListenerConfig(
|
||||
["left-port", "right-port"],
|
||||
["left-location", "right-location"],
|
||||
{"left": "foo", "right": "bar"},
|
||||
),
|
||||
result,
|
||||
)
|
||||
|
||||
class Config(unittest.TestCase):
|
||||
def test_client_unrecognized_options(self):
|
||||
tests = [
|
||||
|
Loading…
Reference in New Issue
Block a user