2024-03-08 11:19:12 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2024-03-08 10:00:34 +01:00
|
|
|
import os
|
|
|
|
import unittest
|
2024-03-08 22:46:19 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
2024-07-03 18:30:40 +02:00
|
|
|
from tests.integration.test_utils import RunSubprocessMixin
|
2022-02-20 21:54:14 +01:00
|
|
|
|
2022-03-01 08:53:24 +01:00
|
|
|
|
2024-03-08 10:00:34 +01:00
|
|
|
def base_path():
|
|
|
|
"""Returns the base path for the project"""
|
2024-06-26 10:01:48 +02:00
|
|
|
return Path(__file__).parent.parent.parent
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_path():
|
|
|
|
"""Returns the path to the tests directory"""
|
2024-06-26 10:01:48 +02:00
|
|
|
return os.path.join(base_path(), "tests/integration")
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def podman_compose_path():
|
|
|
|
"""Returns the path to the podman compose script"""
|
|
|
|
return os.path.join(base_path(), "podman_compose.py")
|
|
|
|
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
|
2024-03-08 10:00:34 +01:00
|
|
|
def test_extends_w_file_subdir(self):
|
|
|
|
"""
|
|
|
|
Test that podman-compose can execute podman-compose -f <file> up with extended File which
|
|
|
|
includes a build context
|
|
|
|
:return:
|
|
|
|
"""
|
2024-06-26 10:01:48 +02:00
|
|
|
main_path = Path(__file__).parent.parent.parent
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
command_up = [
|
|
|
|
"coverage",
|
|
|
|
"run",
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
2024-06-26 10:01:48 +02:00
|
|
|
str(
|
|
|
|
main_path.joinpath(
|
|
|
|
"tests", "integration", "extends_w_file_subdir", "docker-compose.yml"
|
|
|
|
)
|
|
|
|
),
|
2024-03-08 10:00:34 +01:00
|
|
|
"up",
|
|
|
|
"-d",
|
|
|
|
]
|
|
|
|
|
|
|
|
command_check_container = [
|
|
|
|
"coverage",
|
|
|
|
"run",
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
2024-06-26 10:01:48 +02:00
|
|
|
str(
|
|
|
|
main_path.joinpath(
|
|
|
|
"tests", "integration", "extends_w_file_subdir", "docker-compose.yml"
|
|
|
|
)
|
|
|
|
),
|
2024-03-08 10:00:34 +01:00
|
|
|
"ps",
|
|
|
|
"--format",
|
|
|
|
'{{.Image}}',
|
|
|
|
]
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
self.run_subprocess_assert_returncode(command_up)
|
2024-03-08 10:00:34 +01:00
|
|
|
# check container was created and exists
|
2024-03-08 12:14:02 +01:00
|
|
|
out, _ = self.run_subprocess_assert_returncode(command_check_container)
|
2024-03-08 10:00:34 +01:00
|
|
|
self.assertEqual(out, b'localhost/subdir_test:me\n')
|
|
|
|
# cleanup test image(tags)
|
2024-03-08 14:49:00 +01:00
|
|
|
self.run_subprocess_assert_returncode([
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
2024-06-26 10:01:48 +02:00
|
|
|
str(
|
|
|
|
main_path.joinpath(
|
|
|
|
"tests", "integration", "extends_w_file_subdir", "docker-compose.yml"
|
|
|
|
)
|
|
|
|
),
|
2024-03-08 14:49:00 +01:00
|
|
|
"down",
|
|
|
|
])
|
|
|
|
|
|
|
|
self.run_subprocess_assert_returncode([
|
|
|
|
"podman",
|
|
|
|
"rmi",
|
|
|
|
"--force",
|
|
|
|
"localhost/subdir_test:me",
|
|
|
|
])
|
|
|
|
|
2024-03-08 10:00:34 +01:00
|
|
|
# check container did not exists anymore
|
2024-03-08 12:14:02 +01:00
|
|
|
out, _ = self.run_subprocess_assert_returncode(command_check_container)
|
2024-03-08 10:00:34 +01:00
|
|
|
self.assertEqual(out, b'')
|
|
|
|
|
|
|
|
def test_extends_w_empty_service(self):
|
|
|
|
"""
|
|
|
|
Test that podman-compose can execute podman-compose -f <file> up with extended File which
|
2024-03-08 22:46:24 +01:00
|
|
|
includes an empty service. (e.g. if the file is used as placeholder for more complex
|
|
|
|
configurations.)
|
2024-03-08 10:00:34 +01:00
|
|
|
"""
|
2024-06-26 10:01:48 +02:00
|
|
|
main_path = Path(__file__).parent.parent.parent
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
command_up = [
|
|
|
|
"python3",
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
2024-06-26 10:01:48 +02:00
|
|
|
str(
|
|
|
|
main_path.joinpath(
|
|
|
|
"tests", "integration", "extends_w_empty_service", "docker-compose.yml"
|
|
|
|
)
|
|
|
|
),
|
2024-03-08 10:00:34 +01:00
|
|
|
"up",
|
|
|
|
"-d",
|
|
|
|
]
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
self.run_subprocess_assert_returncode(command_up)
|