From 35714c46b10e9900c127341e5a91cabddbb4271d Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Mon, 18 Mar 2019 15:35:22 +0100 Subject: [PATCH] Test all split_port with all valid protocols Signed-off-by: Hannes Ljungberg --- tests/unit/utils_test.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index a4e9c9c5..3cb3be91 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -491,9 +491,12 @@ class PortsTest(unittest.TestCase): assert external_port == [("127.0.0.1", "1000")] def test_split_port_with_protocol(self): - internal_port, external_port = split_port("127.0.0.1:1000:2000/udp") - assert internal_port == ["2000/udp"] - assert external_port == [("127.0.0.1", "1000")] + for protocol in ['tcp', 'udp', 'sctp']: + internal_port, external_port = split_port( + "127.0.0.1:1000:2000/" + protocol + ) + assert internal_port == ["2000/" + protocol] + assert external_port == [("127.0.0.1", "1000")] def test_split_port_with_host_ip_no_port(self): internal_port, external_port = split_port("127.0.0.1::2000") @@ -546,6 +549,10 @@ class PortsTest(unittest.TestCase): with pytest.raises(ValueError): split_port("0.0.0.0:1000:2000:tcp") + def test_split_port_invalid_protocol(self): + with pytest.raises(ValueError): + split_port("0.0.0.0:1000:2000/ftp") + def test_non_matching_length_port_ranges(self): with pytest.raises(ValueError): split_port("0.0.0.0:1000-1010:2000-2002/tcp")