From 5ff24d960bad29b25f3f13115cb76a26ff3d6ac1 Mon Sep 17 00:00:00 2001 From: James Bourbeau Date: Wed, 12 Dec 2018 22:05:35 -0600 Subject: [PATCH] Add test_labels --- tests/test_labels.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_labels.py diff --git a/tests/test_labels.py b/tests/test_labels.py new file mode 100644 index 00000000..1e90cf16 --- /dev/null +++ b/tests/test_labels.py @@ -0,0 +1,37 @@ +""" +Test if labels are supplied correctly to the container +""" +import time +from repo2docker.app import Repo2Docker +from repo2docker import __version__ +import pytest + + +@pytest.mark.parametrize('ref', ['some-branch', None]) +def test_labels(ref, tmpdir): + app = Repo2Docker() + if ref is not None: + argv = ['--ref', ref, str(tmpdir)] + else: + argv = [str(tmpdir)] + app.initialize(argv) + app.debug = True + app.run = False + app.start() # This just build the image and does not run it. + container = app.start_container() + expected_labels = { + 'repo2docker.ref': str(ref), + 'repo2docker.repo': str(tmpdir), + 'repo2docker.version': __version__, + } + + # wait a bit for the container to be ready + # give the container a chance to start + time.sleep(1) + + try: + assert container.labels == expected_labels + finally: + # stop the container + container.stop() + app.wait_for_container(container)