From 24bdfd1e1799909cedbc4916346c1f9b40b18df2 Mon Sep 17 00:00:00 2001 From: Monika Kairaityte Date: Sun, 19 Jan 2025 20:53:55 +0200 Subject: [PATCH] tests/integration: Move test "extends_w_file_subdir" to corresp. dir Signed-off-by: Monika Kairaityte --- .../extends_w_file_subdir/__init__.py | 1 + ...st_podman_compose_extends_w_file_subdir.py | 104 ++++++++++++++++++ tests/integration/test_podman_compose.py | 68 ------------ ...st_podman_compose_extends_w_file_subdir.py | 39 ------- 4 files changed, 105 insertions(+), 107 deletions(-) create mode 100644 tests/integration/extends_w_file_subdir/__init__.py create mode 100644 tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py delete mode 100644 tests/integration/test_podman_compose_extends_w_file_subdir.py diff --git a/tests/integration/extends_w_file_subdir/__init__.py b/tests/integration/extends_w_file_subdir/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/extends_w_file_subdir/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py b/tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py new file mode 100644 index 0000000..23f2638 --- /dev/null +++ b/tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py @@ -0,0 +1,104 @@ +# SPDX-License-Identifier: GPL-2.0 + +import os +import unittest +from pathlib import Path + +from tests.integration.test_podman_compose import podman_compose_path +from tests.integration.test_podman_compose import test_path +from tests.integration.test_utils import RunSubprocessMixin + + +def compose_yaml_path(): + return os.path.join(os.path.join(test_path(), "extends_w_file_subdir"), "docker-compose.yml") + + +class TestComposeExtendsWithFileSubdir(unittest.TestCase, RunSubprocessMixin): + def test_extends_w_file_subdir(self): # when file is Dockerfile for building the image + try: + self.run_subprocess_assert_returncode( + [ + podman_compose_path(), + "-f", + compose_yaml_path(), + "up", + ], + ) + output, _ = self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "ps", + ]) + self.assertIn("extends_w_file_subdir_web_1", str(output)) + finally: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "down", + ]) + + def test_podman_compose_extends_w_file_subdir(self): + """ + Test that podman-compose can execute podman-compose -f up with extended File which + includes a build context + :return: + """ + main_path = Path(__file__).parent.parent.parent.parent + + command_up = [ + "coverage", + "run", + str(main_path.joinpath("podman_compose.py")), + "-f", + str( + main_path.joinpath( + "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" + ) + ), + "up", + "-d", + ] + + command_check_container = [ + "coverage", + "run", + str(main_path.joinpath("podman_compose.py")), + "-f", + str( + main_path.joinpath( + "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" + ) + ), + "ps", + "--format", + '{{.Image}}', + ] + + self.run_subprocess_assert_returncode(command_up) + # check container was created and exists + out, _ = self.run_subprocess_assert_returncode(command_check_container) + self.assertEqual(out, b'localhost/subdir_test:me\n') + # cleanup test image(tags) + self.run_subprocess_assert_returncode([ + str(main_path.joinpath("podman_compose.py")), + "-f", + str( + main_path.joinpath( + "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" + ) + ), + "down", + ]) + + self.run_subprocess_assert_returncode([ + "podman", + "rmi", + "--force", + "localhost/subdir_test:me", + ]) + + # check container did not exists anymore + out, _ = self.run_subprocess_assert_returncode(command_check_container) + self.assertEqual(out, b'') diff --git a/tests/integration/test_podman_compose.py b/tests/integration/test_podman_compose.py index 6fa6b25..69a5fb6 100644 --- a/tests/integration/test_podman_compose.py +++ b/tests/integration/test_podman_compose.py @@ -4,8 +4,6 @@ import os import unittest from pathlib import Path -from tests.integration.test_utils import RunSubprocessMixin - def base_path(): """Returns the base path for the project""" @@ -20,69 +18,3 @@ def test_path(): def podman_compose_path(): """Returns the path to the podman compose script""" return os.path.join(base_path(), "podman_compose.py") - - -class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): - def test_extends_w_file_subdir(self): - """ - Test that podman-compose can execute podman-compose -f up with extended File which - includes a build context - :return: - """ - main_path = Path(__file__).parent.parent.parent - - command_up = [ - "coverage", - "run", - str(main_path.joinpath("podman_compose.py")), - "-f", - str( - main_path.joinpath( - "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" - ) - ), - "up", - "-d", - ] - - command_check_container = [ - "coverage", - "run", - str(main_path.joinpath("podman_compose.py")), - "-f", - str( - main_path.joinpath( - "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" - ) - ), - "ps", - "--format", - '{{.Image}}', - ] - - self.run_subprocess_assert_returncode(command_up) - # check container was created and exists - out, _ = self.run_subprocess_assert_returncode(command_check_container) - self.assertEqual(out, b'localhost/subdir_test:me\n') - # cleanup test image(tags) - self.run_subprocess_assert_returncode([ - str(main_path.joinpath("podman_compose.py")), - "-f", - str( - main_path.joinpath( - "tests", "integration", "extends_w_file_subdir", "docker-compose.yml" - ) - ), - "down", - ]) - - self.run_subprocess_assert_returncode([ - "podman", - "rmi", - "--force", - "localhost/subdir_test:me", - ]) - - # check container did not exists anymore - out, _ = self.run_subprocess_assert_returncode(command_check_container) - self.assertEqual(out, b'') diff --git a/tests/integration/test_podman_compose_extends_w_file_subdir.py b/tests/integration/test_podman_compose_extends_w_file_subdir.py deleted file mode 100644 index 4a8dfa3..0000000 --- a/tests/integration/test_podman_compose_extends_w_file_subdir.py +++ /dev/null @@ -1,39 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -import os -import unittest - -from tests.integration.test_podman_compose import podman_compose_path -from tests.integration.test_podman_compose import test_path -from tests.integration.test_utils import RunSubprocessMixin - - -def compose_yaml_path(): - return os.path.join(os.path.join(test_path(), "extends_w_file_subdir"), "docker-compose.yml") - - -class TestComposeExtendsWithFileSubdir(unittest.TestCase, RunSubprocessMixin): - def test_extends_w_file_subdir(self): # when file is Dockerfile for building the image - try: - self.run_subprocess_assert_returncode( - [ - podman_compose_path(), - "-f", - compose_yaml_path(), - "up", - ], - ) - output, _ = self.run_subprocess_assert_returncode([ - podman_compose_path(), - "-f", - compose_yaml_path(), - "ps", - ]) - self.assertIn("extends_w_file_subdir_web_1", str(output)) - finally: - self.run_subprocess_assert_returncode([ - podman_compose_path(), - "-f", - compose_yaml_path(), - "down", - ])