|
| 1 | +# SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +import os |
| 4 | +import unittest |
| 5 | + |
| 6 | +import requests |
| 7 | + |
| 8 | +from tests.integration.test_podman_compose import podman_compose_path |
| 9 | +from tests.integration.test_podman_compose import test_path |
| 10 | +from tests.integration.test_utils import RunSubprocessMixin |
| 11 | + |
| 12 | + |
| 13 | +def compose_yaml_path(): |
| 14 | + """ "Returns the path to the compose file used for this test module""" |
| 15 | + base_path = os.path.join(test_path(), "build") |
| 16 | + return os.path.join(base_path, "docker-compose.yml") |
| 17 | + |
| 18 | + |
| 19 | +class TestComposeBuild(unittest.TestCase, RunSubprocessMixin): |
| 20 | + def test_build(self): |
| 21 | + try: |
| 22 | + self.run_subprocess_assert_returncode([ |
| 23 | + podman_compose_path(), |
| 24 | + "-f", |
| 25 | + compose_yaml_path(), |
| 26 | + "build", |
| 27 | + "--no-cache", |
| 28 | + ]) |
| 29 | + |
| 30 | + self.run_subprocess_assert_returncode([ |
| 31 | + podman_compose_path(), |
| 32 | + "-f", |
| 33 | + compose_yaml_path(), |
| 34 | + "up", |
| 35 | + "-d", |
| 36 | + ]) |
| 37 | + |
| 38 | + request = requests.get('http://localhost:8080/index.txt') |
| 39 | + self.assertEqual(request.status_code, 200) |
| 40 | + |
| 41 | + alt_request_success = False |
| 42 | + try: |
| 43 | + # FIXME: suspicious behaviour, too often ends up in error |
| 44 | + alt_request = requests.get('http://localhost:8000/index.txt') |
| 45 | + self.assertEqual(alt_request.status_code, 200) |
| 46 | + self.assertIn("ALT buildno=2 port=8000 ", alt_request.text) |
| 47 | + alt_request_success = True |
| 48 | + except requests.exceptions.ConnectionError: |
| 49 | + pass |
| 50 | + |
| 51 | + if alt_request_success: |
| 52 | + output, _ = self.run_subprocess_assert_returncode([ |
| 53 | + "podman", |
| 54 | + "inspect", |
| 55 | + "my-busybox-httpd2", |
| 56 | + ]) |
| 57 | + self.assertIn("httpd_port=8000", str(output)) |
| 58 | + self.assertIn("buildno=2", str(output)) |
| 59 | + finally: |
| 60 | + self.run_subprocess_assert_returncode([ |
| 61 | + podman_compose_path(), |
| 62 | + "-f", |
| 63 | + compose_yaml_path(), |
| 64 | + "down", |
| 65 | + ]) |
0 commit comments