split_port should not break when passed a non-string argument

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-06-28 12:06:03 -07:00
parent 706e2cad65
commit 50a60717f0
2 changed files with 4 additions and 0 deletions

View File

@ -54,6 +54,7 @@ def port_range(start, end, proto, randomly_available_port=False):
def split_port(port):
port = str(port)
match = PORT_SPEC.match(port)
if match is None:
_raise_invalid_port(port)

View File

@ -587,6 +587,9 @@ class PortsTest(unittest.TestCase):
def test_split_port_empty_string(self):
self.assertRaises(ValueError, lambda: split_port(""))
def test_split_port_non_string(self):
assert split_port(1243) == (['1243'], None)
def test_build_port_bindings_with_one_port(self):
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])