0 is a valid value for a published port

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-07-25 16:27:10 -07:00 committed by Joffrey F
parent 770d94376a
commit 1ae83d4139
2 changed files with 7 additions and 1 deletions

View File

@ -343,7 +343,7 @@ class ServicePort(namedtuple('_ServicePort', 'target published protocol mode ext
def normalize_port_dict(port):
return '{external_ip}{has_ext_ip}{published}{is_pub}{target}/{protocol}'.format(
published=port.get('published', ''),
is_pub=(':' if port.get('published') or port.get('external_ip') else ''),
is_pub=(':' if port.get('published') is not None or port.get('external_ip') else ''),
target=port.get('target'),
protocol=port.get('protocol', 'tcp'),
external_ip=port.get('external_ip', ''),

View File

@ -81,6 +81,12 @@ class TestServicePort(object):
'external_ip': '1.1.1.1',
}
def test_repr_published_port_0(self):
port_def = '0:4000'
ports = ServicePort.parse(port_def)
assert len(ports) == 1
assert ports[0].legacy_repr() == port_def + '/tcp'
def test_parse_port_range(self):
ports = ServicePort.parse('25000-25001:4000-4001')
assert len(ports) == 2