2022-02-20 21:54:14 +01:00
|
|
|
from pathlib import Path
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
def capture(command):
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
command,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
)
|
|
|
|
out, err = proc.communicate()
|
|
|
|
return out, err, proc.returncode
|
|
|
|
|
2022-03-01 08:53:24 +01:00
|
|
|
|
2022-02-20 21:54:14 +01:00
|
|
|
def test_podman_compose_extends_w_file_subdir():
|
|
|
|
"""
|
|
|
|
Test that podman-compose can execute podman-compose -f <file> up with extended File which
|
|
|
|
includes a build context
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
main_path = Path(__file__).parent.parent
|
|
|
|
|
|
|
|
command_up = [
|
2023-12-11 00:26:58 +01:00
|
|
|
"coverage",
|
|
|
|
"run",
|
2022-02-20 21:54:14 +01:00
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
|
|
|
str(main_path.joinpath("tests", "extends_w_file_subdir", "docker-compose.yml")),
|
|
|
|
"up",
|
2022-03-01 08:53:24 +01:00
|
|
|
"-d",
|
2022-02-20 21:54:14 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
command_check_container = [
|
2023-12-11 08:46:20 +01:00
|
|
|
"coverage",
|
|
|
|
"run",
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
|
|
|
str(main_path.joinpath("tests", "extends_w_file_subdir", "docker-compose.yml")),
|
2022-02-20 21:54:14 +01:00
|
|
|
"ps",
|
|
|
|
"--format",
|
2023-12-11 08:46:20 +01:00
|
|
|
'{{.Image}}',
|
2022-02-20 21:54:14 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
command_down = [
|
|
|
|
"podman",
|
|
|
|
"rmi",
|
|
|
|
"--force",
|
|
|
|
"localhost/subdir_test:me",
|
2022-10-27 22:38:34 +02:00
|
|
|
"docker.io/library/busybox",
|
2022-02-20 21:54:14 +01:00
|
|
|
]
|
|
|
|
|
2023-04-09 19:49:08 +02:00
|
|
|
out, _, returncode = capture(command_up)
|
2022-02-20 21:54:14 +01:00
|
|
|
assert 0 == returncode
|
|
|
|
# check container was created and exists
|
2023-12-11 08:46:20 +01:00
|
|
|
out, err, returncode = capture(command_check_container)
|
2022-02-20 21:54:14 +01:00
|
|
|
assert 0 == returncode
|
2023-12-11 08:46:20 +01:00
|
|
|
assert b'localhost/subdir_test:me\n' == out
|
2023-04-09 19:49:08 +02:00
|
|
|
out, _, returncode = capture(command_down)
|
2022-02-20 21:54:14 +01:00
|
|
|
# cleanup test image(tags)
|
|
|
|
assert 0 == returncode
|
2023-12-10 07:51:54 +01:00
|
|
|
print('ok')
|
2022-02-20 21:54:14 +01:00
|
|
|
# check container did not exists anymore
|
2023-04-09 19:49:08 +02:00
|
|
|
out, _, returncode = capture(command_check_container)
|
2022-02-20 21:54:14 +01:00
|
|
|
assert 0 == returncode
|
2023-12-11 08:46:20 +01:00
|
|
|
assert b'' == out
|
2023-07-26 15:27:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_podman_compose_extends_w_empty_service():
|
|
|
|
"""
|
|
|
|
Test that podman-compose can execute podman-compose -f <file> up with extended File which
|
|
|
|
includes an empty service. (e.g. if the file is used as placeholder for more complex configurations.)
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
main_path = Path(__file__).parent.parent
|
|
|
|
|
|
|
|
command_up = [
|
|
|
|
"python3",
|
|
|
|
str(main_path.joinpath("podman_compose.py")),
|
|
|
|
"-f",
|
2024-03-07 17:28:06 +01:00
|
|
|
str(main_path.joinpath("tests", "extends_w_empty_service", "docker-compose.yml")),
|
2023-07-26 15:27:30 +02:00
|
|
|
"up",
|
|
|
|
"-d",
|
|
|
|
]
|
|
|
|
|
|
|
|
_, _, returncode = capture(command_up)
|
|
|
|
assert 0 == returncode
|