From: Michael Tremer Date: Wed, 21 Feb 2024 16:27:04 +0000 (+0000) Subject: tests: Add more dedup/merge tests X-Git-Tag: 0.9.18~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54cce4efa1361addf98e5db4d8eac627ddf90e74;p=location%2Flibloc.git tests: Add more dedup/merge tests Signed-off-by: Michael Tremer --- diff --git a/tests/python/networks-dedup.py b/tests/python/networks-dedup.py index 190b367..34a82d4 100644 --- a/tests/python/networks-dedup.py +++ b/tests/python/networks-dedup.py @@ -27,11 +27,14 @@ class Test(unittest.TestCase): # Show even very large diffs self.maxDiff = None - def __test(self, inputs, outputs): + def __test(self, inputs, outputs=None): """ Takes a list of networks that are written to the database and compares the result with the second argument. """ + if outputs is None: + outputs = [network for network, cc, asn in inputs] + with tempfile.NamedTemporaryFile() as f: w = location.Writer() @@ -90,7 +93,51 @@ class Test(unittest.TestCase): ) # The input should match the output - self.__test(networks, [network for network, cc, asn in networks]) + self.__test(networks) + + def test_dedup_with_properties(self): + """ + A more complicated deduplication test where properties have been set + """ + # Nothing should change here because of different countries + self.__test( + ( + ("10.0.0.0/8", "DE", None), + ("10.0.0.0/16", "AT", None), + ("10.0.0.0/24", "DE", None), + ), + ) + + # Nothing should change here because of different ASNs + self.__test( + ( + ("10.0.0.0/8", None, 1000), + ("10.0.0.0/16", None, 2000), + ("10.0.0.0/24", None, 1000), + ), + ) + + # Everything can be merged again + self.__test( + ( + ("10.0.0.0/8", "DE", 1000), + ("10.0.0.0/16", "DE", 1000), + ("10.0.0.0/24", "DE", 1000), + ), + ("10.0.0.0/8",), + ) + + def test_merge(self): + """ + Checks whether the merging algorithm works + """ + self.__test( + ( + ("10.0.0.0/9", None, None), + ("10.128.0.0/9", None, None), + ), + ("10.0.0.0/8",), + ) if __name__ == "__main__":