diff --git a/tests/integration/additional_contexts/__init__.py b/tests/integration/additional_contexts/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/additional_contexts/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_additional_contexts.py b/tests/integration/additional_contexts/test_podman_compose_additional_contexts.py similarity index 90% rename from tests/integration/test_podman_compose_additional_contexts.py rename to tests/integration/additional_contexts/test_podman_compose_additional_contexts.py index 2a6df74..74600d6 100644 --- a/tests/integration/test_podman_compose_additional_contexts.py +++ b/tests/integration/additional_contexts/test_podman_compose_additional_contexts.py @@ -7,8 +7,8 @@ import os import subprocess 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 podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/build/__init__.py b/tests/integration/build/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/tests/integration/build/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_build.py b/tests/integration/build/test_podman_compose_build.py similarity index 93% rename from tests/integration/test_podman_compose_build.py rename to tests/integration/build/test_podman_compose_build.py index ac4ce17..ce9da15 100644 --- a/tests/integration/test_podman_compose_build.py +++ b/tests/integration/build/test_podman_compose_build.py @@ -5,8 +5,8 @@ import unittest import requests -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 podman_compose_path +from tests.integration.test_utils import test_path from tests.integration.test_utils import RunSubprocessMixin diff --git a/tests/integration/build_fail/__init__.py b/tests/integration/build_fail/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/build_fail/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_build_fail.py b/tests/integration/build_fail/test_podman_compose_build_fail.py similarity index 87% rename from tests/integration/test_podman_compose_build_fail.py rename to tests/integration/build_fail/test_podman_compose_build_fail.py index 1bb89a5..44dd920 100644 --- a/tests/integration/test_podman_compose_build_fail.py +++ b/tests/integration/build_fail/test_podman_compose_build_fail.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/build_labels/__init__.py b/tests/integration/build_labels/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/build_labels/test_build_labels.py b/tests/integration/build_labels/test_build_labels.py index aaa37a5..c0709ad 100644 --- a/tests/integration/build_labels/test_build_labels.py +++ b/tests/integration/build_labels/test_build_labels.py @@ -5,9 +5,9 @@ import json 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path class TestBuildLabels(unittest.TestCase, RunSubprocessMixin): diff --git a/tests/integration/build_secrets/__init__.py b/tests/integration/build_secrets/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/build_secrets/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_build_secrets.py b/tests/integration/build_secrets/test_podman_compose_build_secrets.py similarity index 95% rename from tests/integration/test_podman_compose_build_secrets.py rename to tests/integration/build_secrets/test_podman_compose_build_secrets.py index e5360f6..d9a78b4 100644 --- a/tests/integration/test_podman_compose_build_secrets.py +++ b/tests/integration/build_secrets/test_podman_compose_build_secrets.py @@ -7,8 +7,8 @@ import os import subprocess 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 podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/build_ssh/test_build_ssh.py b/tests/integration/build_ssh/test_build_ssh.py index 57e3960..eb61098 100644 --- a/tests/integration/build_ssh/test_build_ssh.py +++ b/tests/integration/build_ssh/test_build_ssh.py @@ -9,9 +9,9 @@ import unittest from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path expected_lines = [ "default: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYQvN9a+toIB6jSs4zY7FMapZnHt80EKCUr/WhLwUum", diff --git a/tests/integration/default_net_behavior/__init__.py b/tests/integration/default_net_behavior/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/default_net_behavior/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_default_net_behavior.py b/tests/integration/default_net_behavior/test_podman_compose_default_net_behavior.py similarity index 94% rename from tests/integration/test_podman_compose_default_net_behavior.py rename to tests/integration/default_net_behavior/test_podman_compose_default_net_behavior.py index 367562a..680f874 100644 --- a/tests/integration/test_podman_compose_default_net_behavior.py +++ b/tests/integration/default_net_behavior/test_podman_compose_default_net_behavior.py @@ -5,9 +5,9 @@ import unittest from parameterized import parameterized -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(scenario): diff --git a/tests/integration/deps/__init__.py b/tests/integration/deps/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/deps/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_deps.py b/tests/integration/deps/test_podman_compose_deps.py similarity index 71% rename from tests/integration/test_podman_compose_deps.py rename to tests/integration/deps/test_podman_compose_deps.py index 17893bf..e15f6ec 100644 --- a/tests/integration/test_podman_compose_deps.py +++ b/tests/integration/deps/test_podman_compose_deps.py @@ -2,9 +2,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(suffix=""): @@ -87,6 +87,58 @@ class TestComposeBaseDeps(unittest.TestCase, RunSubprocessMixin): "down", ]) + def test_podman_compose_run(self): + """ + This will test depends_on as well + """ + run_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "deps", "docker-compose.yaml"), + "run", + "--rm", + "sleep", + "/bin/sh", + "-c", + "wget -q -O - http://web:8000/hosts", + ] + + out, _ = self.run_subprocess_assert_returncode(run_cmd) + self.assertIn(b"127.0.0.1\tlocalhost", out) + + # Run it again to make sure we can run it twice. I saw an issue where a second run, with + # the container left up, would fail + run_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "deps", "docker-compose.yaml"), + "run", + "--rm", + "sleep", + "/bin/sh", + "-c", + "wget -q -O - http://web:8000/hosts", + ] + + out, _ = self.run_subprocess_assert_returncode(run_cmd) + self.assertIn(b"127.0.0.1\tlocalhost", out) + + # This leaves a container running. Not sure it's intended, but it matches docker-compose + down_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "deps", "docker-compose.yaml"), + "down", + ] + + self.run_subprocess_assert_returncode(down_cmd) + class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin): def test_deps_succeeds(self): diff --git a/tests/integration/env-file-tests/__init__.py b/tests/integration/env-file-tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/env-file-tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_env_file.py b/tests/integration/env-file-tests/test_podman_compose_env_file.py similarity index 98% rename from tests/integration/test_podman_compose_env_file.py rename to tests/integration/env-file-tests/test_podman_compose_env_file.py index 5e0dbac..5676dc9 100644 --- a/tests/integration/test_podman_compose_env_file.py +++ b/tests/integration/env-file-tests/test_podman_compose_env_file.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_base_path(): diff --git a/tests/integration/env-tests/__init__.py b/tests/integration/env-tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/env-tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_env.py b/tests/integration/env-tests/test_podman_compose_env.py similarity index 88% rename from tests/integration/test_podman_compose_env.py rename to tests/integration/env-tests/test_podman_compose_env.py index 2eb6d30..351644f 100644 --- a/tests/integration/test_podman_compose_env.py +++ b/tests/integration/env-tests/test_podman_compose_env.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/exit-from/__init__.py b/tests/integration/exit-from/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/exit-from/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_exit_from.py b/tests/integration/exit-from/test_podman_compose_exit_from.py similarity index 71% rename from tests/integration/test_podman_compose_exit_from.py rename to tests/integration/exit-from/test_podman_compose_exit_from.py index 9d0117f..1d36b9d 100644 --- a/tests/integration/test_podman_compose_exit_from.py +++ b/tests/integration/exit-from/test_podman_compose_exit_from.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): @@ -52,3 +52,16 @@ class TestComposeExitFrom(unittest.TestCase, RunSubprocessMixin): compose_yaml_path(), "down", ]) + + def test_podman_compose_exit_from(self): + up_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "exit-from", "docker-compose.yaml"), + "up", + ] + + self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh1"], 1) + self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh2"], 2) diff --git a/tests/integration/extends/__init__.py b/tests/integration/extends/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/extends/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_extends.py b/tests/integration/extends/test_podman_compose_extends.py similarity index 96% rename from tests/integration/test_podman_compose_extends.py rename to tests/integration/extends/test_podman_compose_extends.py index c6a730c..30e6a89 100644 --- a/tests/integration/test_podman_compose_extends.py +++ b/tests/integration/extends/test_podman_compose_extends.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/extends_w_empty_service/__init__.py b/tests/integration/extends_w_empty_service/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/extends_w_empty_service/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_extends_w_empty_service.py b/tests/integration/extends_w_empty_service/test_podman_compose_extends_w_empty_service.py similarity index 54% rename from tests/integration/test_podman_compose_extends_w_empty_service.py rename to tests/integration/extends_w_empty_service/test_podman_compose_extends_w_empty_service.py index 20c7591..8be90b1 100644 --- a/tests/integration/test_podman_compose_extends_w_empty_service.py +++ b/tests/integration/extends_w_empty_service/test_podman_compose_extends_w_empty_service.py @@ -2,10 +2,11 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): @@ -37,3 +38,26 @@ class TestComposeExtendsWithEmptyService(unittest.TestCase, RunSubprocessMixin): compose_yaml_path(), "down", ]) + + def test_podman_compose_extends_w_empty_service(self): + """ + Test that podman-compose can execute podman-compose -f up with extended File which + includes an empty service. (e.g. if the file is used as placeholder for more complex + configurations.) + """ + main_path = Path(__file__).parent.parent.parent.parent + + command_up = [ + "python3", + str(main_path.joinpath("podman_compose.py")), + "-f", + str( + main_path.joinpath( + "tests", "integration", "extends_w_empty_service", "docker-compose.yml" + ) + ), + "up", + "-d", + ] + + self.run_subprocess_assert_returncode(command_up) diff --git a/tests/integration/extends_w_file/__init__.py b/tests/integration/extends_w_file/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/extends_w_file/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_extends_w_file.py b/tests/integration/extends_w_file/test_podman_compose_extends_w_file.py similarity index 90% rename from tests/integration/test_podman_compose_extends_w_file.py rename to tests/integration/extends_w_file/test_podman_compose_extends_w_file.py index a57f51c..406617c 100644 --- a/tests/integration/test_podman_compose_extends_w_file.py +++ b/tests/integration/extends_w_file/test_podman_compose_extends_w_file.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): 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/test_podman_compose.py b/tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py similarity index 61% rename from tests/integration/test_podman_compose.py rename to tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py index e6cba41..a188d06 100644 --- a/tests/integration/test_podman_compose.py +++ b/tests/integration/extends_w_file_subdir/test_podman_compose_extends_w_file_subdir.py @@ -5,31 +5,47 @@ import unittest from pathlib import Path from tests.integration.test_utils import RunSubprocessMixin +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path -def base_path(): - """Returns the base path for the project""" - return Path(__file__).parent.parent.parent +def compose_yaml_path(): + return os.path.join(os.path.join(test_path(), "extends_w_file_subdir"), "docker-compose.yml") -def test_path(): - """Returns the path to the tests directory""" - return os.path.join(base_path(), "tests/integration") +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 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): + 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 + main_path = Path(__file__).parent.parent.parent.parent command_up = [ "coverage", @@ -86,26 +102,3 @@ class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): # check container did not exists anymore out, _ = self.run_subprocess_assert_returncode(command_check_container) self.assertEqual(out, b'') - - def test_extends_w_empty_service(self): - """ - Test that podman-compose can execute podman-compose -f up with extended File which - includes an empty service. (e.g. if the file is used as placeholder for more complex - configurations.) - """ - main_path = Path(__file__).parent.parent.parent - - command_up = [ - "python3", - str(main_path.joinpath("podman_compose.py")), - "-f", - str( - main_path.joinpath( - "tests", "integration", "extends_w_empty_service", "docker-compose.yml" - ) - ), - "up", - "-d", - ] - - self.run_subprocess_assert_returncode(command_up) diff --git a/tests/integration/filesystem/__init__.py b/tests/integration/filesystem/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/filesystem/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_filesystem.py b/tests/integration/filesystem/test_podman_compose_filesystem.py similarity index 90% rename from tests/integration/test_podman_compose_filesystem.py rename to tests/integration/filesystem/test_podman_compose_filesystem.py index afd806c..d78e369 100644 --- a/tests/integration/test_podman_compose_filesystem.py +++ b/tests/integration/filesystem/test_podman_compose_filesystem.py @@ -4,9 +4,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path class TestFilesystem(unittest.TestCase, RunSubprocessMixin): diff --git a/tests/integration/in_pod/__init__.py b/tests/integration/in_pod/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/in_pod/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_in_pod.py b/tests/integration/in_pod/test_podman_compose_in_pod.py similarity index 99% rename from tests/integration/test_podman_compose_in_pod.py rename to tests/integration/in_pod/test_podman_compose_in_pod.py index ed57135..88b1a40 100644 --- a/tests/integration/test_podman_compose_in_pod.py +++ b/tests/integration/in_pod/test_podman_compose_in_pod.py @@ -8,7 +8,7 @@ from tests.integration.test_utils import RunSubprocessMixin def base_path(): """Returns the base path for the project""" - return os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + return os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) def test_path(): diff --git a/tests/integration/include/__init__.py b/tests/integration/include/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/include/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_include.py b/tests/integration/include/test_podman_compose_include.py similarity index 97% rename from tests/integration/test_podman_compose_include.py rename to tests/integration/include/test_podman_compose_include.py index dcde390..e5e915c 100644 --- a/tests/integration/test_podman_compose_include.py +++ b/tests/integration/include/test_podman_compose_include.py @@ -12,7 +12,7 @@ class TestPodmanComposeInclude(unittest.TestCase, RunSubprocessMixin): Test that podman-compose can execute podman-compose -f up with include :return: """ - main_path = Path(__file__).parent.parent.parent + main_path = Path(__file__).parent.parent.parent.parent command_up = [ "coverage", diff --git a/tests/integration/interpolation/__init__.py b/tests/integration/interpolation/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/interpolation/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_interpolation.py b/tests/integration/interpolation/test_podman_compose_interpolation.py similarity index 92% rename from tests/integration/test_podman_compose_interpolation.py rename to tests/integration/interpolation/test_podman_compose_interpolation.py index 53eb9ac..4dbf682 100644 --- a/tests/integration/test_podman_compose_interpolation.py +++ b/tests/integration/interpolation/test_podman_compose_interpolation.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/ipam_default/__init__.py b/tests/integration/ipam_default/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/ipam_default/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_ipam_default.py b/tests/integration/ipam_default/test_podman_compose_ipam_default.py similarity index 93% rename from tests/integration/test_podman_compose_ipam_default.py rename to tests/integration/ipam_default/test_podman_compose_ipam_default.py index 1cafb7a..18ad0d0 100644 --- a/tests/integration/test_podman_compose_ipam_default.py +++ b/tests/integration/ipam_default/test_podman_compose_ipam_default.py @@ -4,9 +4,9 @@ import json 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/lifetime/test_lifetime.py b/tests/integration/lifetime/test_lifetime.py index 996f5ee..6d29f05 100644 --- a/tests/integration/lifetime/test_lifetime.py +++ b/tests/integration/lifetime/test_lifetime.py @@ -6,9 +6,9 @@ import unittest from parameterized import parameterized -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path class TestLifetime(unittest.TestCase, RunSubprocessMixin): diff --git a/tests/integration/multicompose/__init__.py b/tests/integration/multicompose/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/multicompose/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_multicompose.py b/tests/integration/multicompose/test_podman_compose_multicompose.py similarity index 96% rename from tests/integration/test_podman_compose_multicompose.py rename to tests/integration/multicompose/test_podman_compose_multicompose.py index 339292a..d400ecf 100644 --- a/tests/integration/test_podman_compose_multicompose.py +++ b/tests/integration/multicompose/test_podman_compose_multicompose.py @@ -3,9 +3,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/nethost/__init__.py b/tests/integration/nethost/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/nethost/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_nethost.py b/tests/integration/nethost/test_podman_compose_nethost.py similarity index 93% rename from tests/integration/test_podman_compose_nethost.py rename to tests/integration/nethost/test_podman_compose_nethost.py index fe93aae..e8c232d 100644 --- a/tests/integration/test_podman_compose_nethost.py +++ b/tests/integration/nethost/test_podman_compose_nethost.py @@ -5,9 +5,9 @@ import unittest import requests -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/nets_test1/__init__.py b/tests/integration/nets_test1/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/nets_test1/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_nets_test1.py b/tests/integration/nets_test1/test_podman_compose_nets_test1.py similarity index 95% rename from tests/integration/test_podman_compose_nets_test1.py rename to tests/integration/nets_test1/test_podman_compose_nets_test1.py index 652ebce..916be05 100644 --- a/tests/integration/test_podman_compose_nets_test1.py +++ b/tests/integration/nets_test1/test_podman_compose_nets_test1.py @@ -6,9 +6,9 @@ import unittest import requests -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/nets_test2/__init__.py b/tests/integration/nets_test2/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/nets_test2/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_nets_test2.py b/tests/integration/nets_test2/test_podman_compose_nets_test2.py similarity index 95% rename from tests/integration/test_podman_compose_nets_test2.py rename to tests/integration/nets_test2/test_podman_compose_nets_test2.py index e9b0a8a..73590ba 100644 --- a/tests/integration/test_podman_compose_nets_test2.py +++ b/tests/integration/nets_test2/test_podman_compose_nets_test2.py @@ -6,9 +6,9 @@ import unittest import requests -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/network/__init__.py b/tests/integration/network/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/network/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_networks.py b/tests/integration/network/test_podman_compose_network.py similarity index 76% rename from tests/integration/test_podman_compose_networks.py rename to tests/integration/network/test_podman_compose_network.py index de3982b..b9dc4d9 100644 --- a/tests/integration/test_podman_compose_networks.py +++ b/tests/integration/network/test_podman_compose_network.py @@ -10,9 +10,9 @@ Tests the podman networking parameters 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path class TestPodmanComposeNetwork(RunSubprocessMixin, unittest.TestCase): @@ -114,3 +114,28 @@ class TestPodmanComposeNetwork(RunSubprocessMixin, unittest.TestCase): ip, mac = values self.assertIn(f"ether {mac}", out.decode('utf-8')) self.assertIn(f"inet {ip}/", out.decode('utf-8')) + + def test_down_with_network(self): + try: + self.run_subprocess_assert_returncode([ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "network", "docker-compose.yml"), + "up", + "-d", + ]) + output, _, _ = self.run_subprocess(["podman", "network", "ls"]) + self.assertIn("network_mystack", output.decode()) + finally: + self.run_subprocess_assert_returncode([ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "network", "docker-compose.yml"), + "down", + ]) + output, _, _ = self.run_subprocess(["podman", "network", "ls"]) + self.assertNotIn("network_mystack", output.decode()) diff --git a/tests/integration/network_scoped_aliases/__init__.py b/tests/integration/network_scoped_aliases/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/network_scoped_aliases/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_network_scoped_aliases.py b/tests/integration/network_scoped_aliases/test_podman_compose_network_scoped_aliases.py similarity index 94% rename from tests/integration/test_podman_compose_network_scoped_aliases.py rename to tests/integration/network_scoped_aliases/test_podman_compose_network_scoped_aliases.py index 8e478fa..804d77a 100644 --- a/tests/integration/test_podman_compose_network_scoped_aliases.py +++ b/tests/integration/network_scoped_aliases/test_podman_compose_network_scoped_aliases.py @@ -4,9 +4,9 @@ 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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path class TestPodmanComposeNetworkScopedAliases(RunSubprocessMixin, unittest.TestCase): diff --git a/tests/integration/ports/__init__.py b/tests/integration/ports/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/ports/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/ports/test_podman_compose_ports.py b/tests/integration/ports/test_podman_compose_ports.py new file mode 100644 index 0000000..aa0b13e --- /dev/null +++ b/tests/integration/ports/test_podman_compose_ports.py @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: GPL-2.0 + +""" +test_podman_compose_up_down.py + +Tests the podman compose up and down commands used to create and remove services. +""" + +# pylint: disable=redefined-outer-name +import os +import unittest + +from tests.integration.test_utils import RunSubprocessMixin +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path + + +class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): + def test_up_with_ports(self): + up_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "ports", "docker-compose.yml"), + "up", + "-d", + "--force-recreate", + ] + + down_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "ports", "docker-compose.yml"), + "down", + "--volumes", + ] + + try: + self.run_subprocess_assert_returncode(up_cmd) + + finally: + self.run_subprocess_assert_returncode(down_cmd) + + def test_down_with_orphans(self): + container_id, _ = self.run_subprocess_assert_returncode([ + "podman", + "run", + "--rm", + "-d", + "nopush/podman-compose-test", + "dumb-init", + "/bin/busybox", + "httpd", + "-f", + "-h", + "/etc/", + "-p", + "8000", + ]) + + down_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "ports", "docker-compose.yml"), + "down", + "--volumes", + "--remove-orphans", + ] + + self.run_subprocess_assert_returncode(down_cmd) + + self.run_subprocess_assert_returncode( + [ + "podman", + "container", + "exists", + container_id.decode("utf-8"), + ], + 1, + ) diff --git a/tests/integration/profile/__init__.py b/tests/integration/profile/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/profile/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_config.py b/tests/integration/profile/test_podman_compose_config.py similarity index 95% rename from tests/integration/test_podman_compose_config.py rename to tests/integration/profile/test_podman_compose_config.py index 8a7b637..b1d1f56 100644 --- a/tests/integration/test_podman_compose_config.py +++ b/tests/integration/profile/test_podman_compose_config.py @@ -12,9 +12,9 @@ import unittest from parameterized import parameterized -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def profile_compose_file(): diff --git a/tests/integration/test_podman_compose_up_down.py b/tests/integration/profile/test_podman_compose_up_down.py similarity index 95% rename from tests/integration/test_podman_compose_up_down.py rename to tests/integration/profile/test_podman_compose_up_down.py index f2f554c..be95f13 100644 --- a/tests/integration/test_podman_compose_up_down.py +++ b/tests/integration/profile/test_podman_compose_up_down.py @@ -12,9 +12,9 @@ import unittest from parameterized import parameterized -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 +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path def profile_compose_file(): 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", - ]) diff --git a/tests/integration/test_podman_compose_tests.py b/tests/integration/test_podman_compose_tests.py deleted file mode 100644 index f5ac152..0000000 --- a/tests/integration/test_podman_compose_tests.py +++ /dev/null @@ -1,214 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -""" -test_podman_compose_up_down.py - -Tests the podman compose up and down commands used to create and remove services. -""" - -# pylint: disable=redefined-outer-name -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 - - -class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): - def test_exit_from(self): - up_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "exit-from", "docker-compose.yaml"), - "up", - ] - - self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh1"], 1) - self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh2"], 2) - - def test_run(self): - """ - This will test depends_on as well - """ - run_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "deps", "docker-compose.yaml"), - "run", - "--rm", - "sleep", - "/bin/sh", - "-c", - "wget -q -O - http://web:8000/hosts", - ] - - out, _ = self.run_subprocess_assert_returncode(run_cmd) - self.assertIn(b"127.0.0.1\tlocalhost", out) - - # Run it again to make sure we can run it twice. I saw an issue where a second run, with - # the container left up, would fail - run_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "deps", "docker-compose.yaml"), - "run", - "--rm", - "sleep", - "/bin/sh", - "-c", - "wget -q -O - http://web:8000/hosts", - ] - - out, _ = self.run_subprocess_assert_returncode(run_cmd) - self.assertIn(b"127.0.0.1\tlocalhost", out) - - # This leaves a container running. Not sure it's intended, but it matches docker-compose - down_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "deps", "docker-compose.yaml"), - "down", - ] - - self.run_subprocess_assert_returncode(down_cmd) - - def test_up_with_ports(self): - up_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "ports", "docker-compose.yml"), - "up", - "-d", - "--force-recreate", - ] - - down_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "ports", "docker-compose.yml"), - "down", - "--volumes", - ] - - try: - self.run_subprocess_assert_returncode(up_cmd) - - finally: - self.run_subprocess_assert_returncode(down_cmd) - - def test_down_with_vols(self): - up_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "vol", "docker-compose.yaml"), - "up", - "-d", - ] - - down_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "vol", "docker-compose.yaml"), - "down", - "--volumes", - ] - - try: - self.run_subprocess_assert_returncode(["podman", "volume", "create", "my-app-data"]) - self.run_subprocess_assert_returncode([ - "podman", - "volume", - "create", - "actual-name-of-volume", - ]) - - self.run_subprocess_assert_returncode(up_cmd) - self.run_subprocess(["podman", "inspect", "volume", ""]) - - finally: - out, _, return_code = self.run_subprocess(down_cmd) - self.run_subprocess(["podman", "volume", "rm", "my-app-data"]) - self.run_subprocess(["podman", "volume", "rm", "actual-name-of-volume"]) - self.assertEqual(return_code, 0) - - def test_down_with_orphans(self): - container_id, _ = self.run_subprocess_assert_returncode([ - "podman", - "run", - "--rm", - "-d", - "nopush/podman-compose-test", - "dumb-init", - "/bin/busybox", - "httpd", - "-f", - "-h", - "/etc/", - "-p", - "8000", - ]) - - down_cmd = [ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "ports", "docker-compose.yml"), - "down", - "--volumes", - "--remove-orphans", - ] - - self.run_subprocess_assert_returncode(down_cmd) - - self.run_subprocess_assert_returncode( - [ - "podman", - "container", - "exists", - container_id.decode("utf-8"), - ], - 1, - ) - - def test_down_with_network(self): - try: - self.run_subprocess_assert_returncode([ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "network", "docker-compose.yml"), - "up", - "-d", - ]) - output, _, _ = self.run_subprocess(["podman", "network", "ls"]) - self.assertIn("network_mystack", output.decode()) - finally: - self.run_subprocess_assert_returncode([ - "coverage", - "run", - podman_compose_path(), - "-f", - os.path.join(test_path(), "network", "docker-compose.yml"), - "down", - ]) - output, _, _ = self.run_subprocess(["podman", "network", "ls"]) - self.assertNotIn("network_mystack", output.decode()) diff --git a/tests/integration/test_utils.py b/tests/integration/test_utils.py index c0faf32..475762d 100644 --- a/tests/integration/test_utils.py +++ b/tests/integration/test_utils.py @@ -3,6 +3,22 @@ import os import subprocess import time +from pathlib import Path + + +def base_path(): + """Returns the base path for the project""" + return Path(__file__).parent.parent.parent + + +def test_path(): + """Returns the path to the tests directory""" + return os.path.join(base_path(), "tests/integration") + + +def podman_compose_path(): + """Returns the path to the podman compose script""" + return os.path.join(base_path(), "podman_compose.py") class RunSubprocessMixin: diff --git a/tests/integration/ulimit_build/__init__.py b/tests/integration/ulimit_build/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/ulimit_build/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/test_podman_compose_build_ulimits.py b/tests/integration/ulimit_build/test_podman_compose_build_ulimits.py similarity index 95% rename from tests/integration/test_podman_compose_build_ulimits.py rename to tests/integration/ulimit_build/test_podman_compose_build_ulimits.py index d578d77..f805f82 100644 --- a/tests/integration/test_podman_compose_build_ulimits.py +++ b/tests/integration/ulimit_build/test_podman_compose_build_ulimits.py @@ -7,8 +7,8 @@ import os import subprocess 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 podman_compose_path +from tests.integration.test_utils import test_path def compose_yaml_path(): diff --git a/tests/integration/vol/__init__.py b/tests/integration/vol/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration/vol/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/integration/vol/test_podman_compose_vol.py b/tests/integration/vol/test_podman_compose_vol.py new file mode 100644 index 0000000..31c1e8b --- /dev/null +++ b/tests/integration/vol/test_podman_compose_vol.py @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0 + +""" +test_podman_compose_up_down.py + +Tests the podman compose up and down commands used to create and remove services. +""" + +# pylint: disable=redefined-outer-name +import os +import unittest + +from tests.integration.test_utils import RunSubprocessMixin +from tests.integration.test_utils import podman_compose_path +from tests.integration.test_utils import test_path + + +class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): + def test_down_with_vols(self): + up_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "vol", "docker-compose.yaml"), + "up", + "-d", + ] + + down_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + os.path.join(test_path(), "vol", "docker-compose.yaml"), + "down", + "--volumes", + ] + + try: + self.run_subprocess_assert_returncode(["podman", "volume", "create", "my-app-data"]) + self.run_subprocess_assert_returncode([ + "podman", + "volume", + "create", + "actual-name-of-volume", + ]) + + self.run_subprocess_assert_returncode(up_cmd) + self.run_subprocess(["podman", "inspect", "volume", ""]) + + finally: + out, _, return_code = self.run_subprocess(down_cmd) + self.run_subprocess(["podman", "volume", "rm", "my-app-data"]) + self.run_subprocess(["podman", "volume", "rm", "actual-name-of-volume"]) + self.assertEqual(return_code, 0)