Migrate tests to unittest

unittest is much more straightforward without any magic. In a small
project like podman-compose being easy to understand is more important
than features.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
This commit is contained in:
Povilas Kanapickas
2024-03-08 11:00:34 +02:00
parent 7539257ee8
commit 23fe9e7e1d
17 changed files with 806 additions and 880 deletions

View File

@ -1,8 +1,9 @@
from pathlib import Path
import subprocess
import unittest
def capture(command):
def run_subprocess(command):
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
@ -12,61 +13,62 @@ def capture(command):
return out, err, proc.returncode
def test_podman_compose_include():
"""
Test that podman-compose can execute podman-compose -f <file> up with include
:return:
"""
main_path = Path(__file__).parent.parent
class TestPodmanComposeInclude(unittest.TestCase):
def test_podman_compose_include(self):
"""
Test that podman-compose can execute podman-compose -f <file> up with include
:return:
"""
main_path = Path(__file__).parent.parent
command_up = [
"coverage",
"run",
str(main_path.joinpath("podman_compose.py")),
"-f",
str(main_path.joinpath("tests", "include", "docker-compose.yaml")),
"up",
"-d",
]
command_up = [
"coverage",
"run",
str(main_path.joinpath("podman_compose.py")),
"-f",
str(main_path.joinpath("tests", "include", "docker-compose.yaml")),
"up",
"-d",
]
command_check_container = [
"podman",
"ps",
"-a",
"--filter",
"label=io.podman.compose.project=include",
"--format",
'"{{.Image}}"',
]
command_check_container = [
"podman",
"ps",
"-a",
"--filter",
"label=io.podman.compose.project=include",
"--format",
'"{{.Image}}"',
]
command_container_id = [
"podman",
"ps",
"-a",
"--filter",
"label=io.podman.compose.project=include",
"--format",
'"{{.ID}}"',
]
command_container_id = [
"podman",
"ps",
"-a",
"--filter",
"label=io.podman.compose.project=include",
"--format",
'"{{.ID}}"',
]
command_down = ["podman", "rm", "--force", "CONTAINER_ID"]
command_down = ["podman", "rm", "--force", "CONTAINER_ID"]
out, _, returncode = capture(command_up)
assert 0 == returncode
out, _, returncode = capture(command_check_container)
assert 0 == returncode
assert out == b'"docker.io/library/busybox:latest"\n'
# Get container ID to remove it
out, _, returncode = capture(command_container_id)
assert 0 == returncode
assert out != b""
container_id = out.decode().strip().replace('"', "")
command_down[3] = container_id
out, _, returncode = capture(command_down)
# cleanup test image(tags)
assert 0 == returncode
assert out != b""
# check container did not exists anymore
out, _, returncode = capture(command_check_container)
assert 0 == returncode
assert out == b""
out, _, returncode = run_subprocess(command_up)
self.assertEqual(returncode, 0)
out, _, returncode = run_subprocess(command_check_container)
self.assertEqual(returncode, 0)
self.assertEqual(out, b'"docker.io/library/busybox:latest"\n')
# Get container ID to remove it
out, _, returncode = run_subprocess(command_container_id)
self.assertEqual(returncode, 0)
self.assertNotEqual(out, b"")
container_id = out.decode().strip().replace('"', "")
command_down[3] = container_id
out, _, returncode = run_subprocess(command_down)
# cleanup test image(tags)
self.assertEqual(returncode, 0)
self.assertNotEqual(out, b"")
# check container did not exists anymore
out, _, returncode = run_subprocess(command_check_container)
self.assertEqual(returncode, 0)
self.assertEqual(out, b"")