From b314ba90cd1060c2fe81cbb80fe18378af733383 Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 29 Jun 2020 09:03:14 +0200 Subject: [PATCH] test new port argument possibilities --- tests/unit/test_args.py | 5 ----- tests/unit/test_ports.py | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index 5e8c2484..e5fd2c1a 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -3,7 +3,6 @@ Test argument parsing and r2d construction """ import os import pytest -import logging from repo2docker.__main__ import make_r2d from repo2docker import __version__ @@ -71,10 +70,6 @@ def test_run_required(): with pytest.raises(SystemExit): make_r2d(["--no-run", "-p", "8000:8000", "."]) - # Can't publish any ports while running if we don't specify a command explicitly - with pytest.raises(SystemExit): - make_r2d(["-p", "8000:8000", "."]) - def test_clean(): """ diff --git a/tests/unit/test_ports.py b/tests/unit/test_ports.py index edb71424..445e6c4c 100644 --- a/tests/unit/test_ports.py +++ b/tests/unit/test_ports.py @@ -13,6 +13,7 @@ import docker import pytest from repo2docker.app import Repo2Docker +from repo2docker.__main__ import make_r2d def read_port_mapping_response( @@ -95,7 +96,7 @@ def read_port_mapping_response( else: break else: - pytest.fail("Never succeded in talking to %s" % url) + pytest.fail("Never succeeded in talking to %s" % url) assert "Directory listing" in r.text @@ -113,3 +114,16 @@ def test_port_mapping(request, tmpdir, host, protocol): """Test a port mapping""" port = str(random.randint(50000, 51000)) read_port_mapping_response(request, tmpdir, host=host, port=port, protocol=protocol) + + +@pytest.mark.parametrize( + "port_str, port_dict", + [ + ("8000", {"8000/tcp": "8000"}), + ("8000:9000", {"9000/tcp": "8000"}), + ("127.0.0.1:8000:9000", {"9000/tcp": ("127.0.0.1", "8000")}), + ], +) +def test_port_args(port_str, port_dict): + app = make_r2d(["-p", port_str, "."]) + assert app.ports == port_dict