diff --git a/tests/integration/nets_test3/docker-compose.yml b/tests/integration/nets_test3/docker-compose.yml index a492068..cabd0d4 100644 --- a/tests/integration/nets_test3/docker-compose.yml +++ b/tests/integration/nets_test3/docker-compose.yml @@ -41,5 +41,5 @@ services: aliases: - alias21 volumes: - - ./test2.txt:/var/www/html/index.txt:ro,z + - ./test3.txt:/var/www/html/index.txt:ro,z diff --git a/tests/integration/nets_test3/test3.txt b/tests/integration/nets_test3/test3.txt new file mode 100644 index 0000000..df6b0d2 --- /dev/null +++ b/tests/integration/nets_test3/test3.txt @@ -0,0 +1 @@ +test3 diff --git a/tests/integration/nets_test3/test_podman_compose_nets_test3.py b/tests/integration/nets_test3/test_podman_compose_nets_test3.py new file mode 100644 index 0000000..6d4a043 --- /dev/null +++ b/tests/integration/nets_test3/test_podman_compose_nets_test3.py @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: GPL-2.0 + +import os +import unittest + +from parameterized import parameterized + +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(): + return os.path.join(os.path.join(test_path(), "nets_test3"), "docker-compose.yml") + + +class TestComposeNetsTest3(unittest.TestCase, RunSubprocessMixin): + # test if services can access the networks of other services using their respective aliases + @parameterized.expand([ + ("nets_test3_web2_1", "web3", b"test3", 0), + ("nets_test3_web2_1", "alias11", b"test3", 0), + ("nets_test3_web2_1", "alias12", b"test3", 0), + ("nets_test3_web2_1", "alias21", b"test3", 0), + ("nets_test3_web1_1", "web3", b"test3", 0), + ("nets_test3_web1_1", "alias11", b"test3", 0), + ("nets_test3_web1_1", "alias12", b"test3", 0), + # connection fails as web1 service does not know net2 and its aliases + ("nets_test3_web1_1", "alias21", b"", 1), + ]) + def test_nets_test3( + self, container_name, nework_alias_name, expected_text, expected_returncode + ): + try: + self.run_subprocess_assert_returncode( + [ + podman_compose_path(), + "-f", + compose_yaml_path(), + "up", + "-d", + ], + ) + # check connection from different services to network aliases of web3 service + cmd = [ + "podman", + "exec", + "-it", + f"{container_name}", + "/bin/busybox", + "wget", + "-O", + "-", + "-o", + "/dev/null", + f"http://{nework_alias_name}:8001/index.txt", + ] + out, _, returncode = self.run_subprocess(cmd) + self.assertEqual(expected_returncode, returncode) + self.assertEqual(expected_text, out.strip()) + finally: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "down", + "-t", + "0", + ])