diff --git a/test/webhost/test_port_allocation.py b/test/webhost/test_port_allocation.py index 4fbf32e6ed..76727ae5cd 100644 --- a/test/webhost/test_port_allocation.py +++ b/test/webhost/test_port_allocation.py @@ -6,7 +6,7 @@ from WebHostLib.customserver import parse_game_ports, create_random_port_socket, ci = bool(os.environ.get("CI")) -class TestWebDescriptions(unittest.TestCase): +class TestPortAllocating(unittest.TestCase): def test_parse_game_ports(self) -> None: """Ensure that game ports with ranges are parsed correctly""" val = parse_game_ports(("1000-2000", "2000-5000", "1000-2000", 20, 40, "20", "0")) @@ -27,6 +27,19 @@ class TestWebDescriptions(unittest.TestCase): self.assertListEqual(val.weights, [1001, 4002, 5003, 5004, 5005, 5006], "Cumulative weights are not the expected value") + val = parse_game_ports(()) + self.assertListEqual(val.parsed_ports, [], "Empty list of game port returned something") + self.assertFalse(val.ephemeral_allowed, "Empty list returned that ephemeral is allowed") + + val = parse_game_ports((0,)) + self.assertListEqual(val.parsed_ports, [], "Empty list of ranges returned something") + self.assertTrue(val.ephemeral_allowed, "List with just 0 is not allowing ephemeral ports") + + val = parse_game_ports((1,)) + self.assertEqual(val.parsed_ports, [range(1,2)], "Parsed ports doesn't contain the expected values") + self.assertFalse(val.ephemeral_allowed, "List with just single port returned that ephemeral is allowed") + + def test_parse_game_port_errors(self) -> None: """Ensure that game ports with incorrect values raise the expected error""" with self.assertRaises(ValueError, msg="Negative numbers didn't get interpreted as an invalid range"):