Merge pull request #1113 from mokibit/categorize-integration-tests

tests/integration: Categorize integration tests
This commit is contained in:
Povilas Kanapickas 2025-01-23 02:17:08 +02:00 committed by GitHub
commit d79ff01e77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
64 changed files with 386 additions and 347 deletions

View File

@ -0,0 +1 @@

View File

@ -7,8 +7,8 @@ import os
import subprocess
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
def compose_yaml_path():

View File

@ -0,0 +1 @@

View File

@ -5,8 +5,8 @@ import unittest
import requests
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
from tests.integration.test_utils import RunSubprocessMixin

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -5,9 +5,9 @@ import json
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestBuildLabels(unittest.TestCase, RunSubprocessMixin):

View File

@ -0,0 +1 @@

View File

@ -7,8 +7,8 @@ import os
import subprocess
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
def compose_yaml_path():

View File

@ -9,9 +9,9 @@ import unittest
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
expected_lines = [
"default: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYQvN9a+toIB6jSs4zY7FMapZnHt80EKCUr/WhLwUum",

View File

@ -0,0 +1 @@

View File

@ -5,9 +5,9 @@ import unittest
from parameterized import parameterized
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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(scenario):

View File

@ -0,0 +1 @@

View File

@ -2,9 +2,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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(suffix=""):
@ -87,6 +87,58 @@ class TestComposeBaseDeps(unittest.TestCase, RunSubprocessMixin):
"down",
])
def test_podman_compose_run(self):
"""
This will test depends_on as well
"""
run_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"run",
"--rm",
"sleep",
"/bin/sh",
"-c",
"wget -q -O - http://web:8000/hosts",
]
out, _ = self.run_subprocess_assert_returncode(run_cmd)
self.assertIn(b"127.0.0.1\tlocalhost", out)
# Run it again to make sure we can run it twice. I saw an issue where a second run, with
# the container left up, would fail
run_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"run",
"--rm",
"sleep",
"/bin/sh",
"-c",
"wget -q -O - http://web:8000/hosts",
]
out, _ = self.run_subprocess_assert_returncode(run_cmd)
self.assertIn(b"127.0.0.1\tlocalhost", out)
# This leaves a container running. Not sure it's intended, but it matches docker-compose
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"down",
]
self.run_subprocess_assert_returncode(down_cmd)
class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
def test_deps_succeeds(self):

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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_base_path():

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():
@ -52,3 +52,16 @@ class TestComposeExitFrom(unittest.TestCase, RunSubprocessMixin):
compose_yaml_path(),
"down",
])
def test_podman_compose_exit_from(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "exit-from", "docker-compose.yaml"),
"up",
]
self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh1"], 1)
self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh2"], 2)

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -2,10 +2,11 @@
import os
import unittest
from pathlib import Path
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():
@ -37,3 +38,26 @@ class TestComposeExtendsWithEmptyService(unittest.TestCase, RunSubprocessMixin):
compose_yaml_path(),
"down",
])
def test_podman_compose_extends_w_empty_service(self):
"""
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.)
"""
main_path = Path(__file__).parent.parent.parent.parent
command_up = [
"python3",
str(main_path.joinpath("podman_compose.py")),
"-f",
str(
main_path.joinpath(
"tests", "integration", "extends_w_empty_service", "docker-compose.yml"
)
),
"up",
"-d",
]
self.run_subprocess_assert_returncode(command_up)

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -5,31 +5,47 @@ import unittest
from pathlib import Path
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 base_path():
"""Returns the base path for the project"""
return Path(__file__).parent.parent.parent
def compose_yaml_path():
return os.path.join(os.path.join(test_path(), "extends_w_file_subdir"), "docker-compose.yml")
def test_path():
"""Returns the path to the tests directory"""
return os.path.join(base_path(), "tests/integration")
class TestComposeExtendsWithFileSubdir(unittest.TestCase, RunSubprocessMixin):
def test_extends_w_file_subdir(self): # when file is Dockerfile for building the image
try:
self.run_subprocess_assert_returncode(
[
podman_compose_path(),
"-f",
compose_yaml_path(),
"up",
],
)
output, _ = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"ps",
])
self.assertIn("extends_w_file_subdir_web_1", str(output))
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"down",
])
def podman_compose_path():
"""Returns the path to the podman compose script"""
return os.path.join(base_path(), "podman_compose.py")
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
def test_extends_w_file_subdir(self):
def test_podman_compose_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:
"""
main_path = Path(__file__).parent.parent.parent
main_path = Path(__file__).parent.parent.parent.parent
command_up = [
"coverage",
@ -86,26 +102,3 @@ class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
# check container did not exists anymore
out, _ = self.run_subprocess_assert_returncode(command_check_container)
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
includes an empty service. (e.g. if the file is used as placeholder for more complex
configurations.)
"""
main_path = Path(__file__).parent.parent.parent
command_up = [
"python3",
str(main_path.joinpath("podman_compose.py")),
"-f",
str(
main_path.joinpath(
"tests", "integration", "extends_w_empty_service", "docker-compose.yml"
)
),
"up",
"-d",
]
self.run_subprocess_assert_returncode(command_up)

View File

@ -0,0 +1 @@

View File

@ -4,9 +4,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestFilesystem(unittest.TestCase, RunSubprocessMixin):

View File

@ -0,0 +1 @@

View File

@ -8,7 +8,7 @@ from tests.integration.test_utils import RunSubprocessMixin
def base_path():
"""Returns the base path for the project"""
return os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
def test_path():

View File

@ -0,0 +1 @@

View File

@ -12,7 +12,7 @@ class TestPodmanComposeInclude(unittest.TestCase, RunSubprocessMixin):
Test that podman-compose can execute podman-compose -f <file> up with include
:return:
"""
main_path = Path(__file__).parent.parent.parent
main_path = Path(__file__).parent.parent.parent.parent
command_up = [
"coverage",

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -4,9 +4,9 @@ import json
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -6,9 +6,9 @@ import unittest
from parameterized import parameterized
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestLifetime(unittest.TestCase, RunSubprocessMixin):

View File

@ -0,0 +1 @@

View File

@ -3,9 +3,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -5,9 +5,9 @@ import unittest
import requests
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -6,9 +6,9 @@ import unittest
import requests
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -6,9 +6,9 @@ import unittest
import requests
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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():

View File

@ -0,0 +1 @@

View File

@ -10,9 +10,9 @@ Tests the podman networking parameters
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestPodmanComposeNetwork(RunSubprocessMixin, unittest.TestCase):
@ -114,3 +114,28 @@ class TestPodmanComposeNetwork(RunSubprocessMixin, unittest.TestCase):
ip, mac = values
self.assertIn(f"ether {mac}", out.decode('utf-8'))
self.assertIn(f"inet {ip}/", out.decode('utf-8'))
def test_down_with_network(self):
try:
self.run_subprocess_assert_returncode([
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "network", "docker-compose.yml"),
"up",
"-d",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertIn("network_mystack", output.decode())
finally:
self.run_subprocess_assert_returncode([
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "network", "docker-compose.yml"),
"down",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertNotIn("network_mystack", output.decode())

View File

@ -0,0 +1 @@

View File

@ -4,9 +4,9 @@
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestPodmanComposeNetworkScopedAliases(RunSubprocessMixin, unittest.TestCase):

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,85 @@
# SPDX-License-Identifier: GPL-2.0
"""
test_podman_compose_up_down.py
Tests the podman compose up and down commands used to create and remove services.
"""
# pylint: disable=redefined-outer-name
import os
import unittest
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
def test_up_with_ports(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"up",
"-d",
"--force-recreate",
]
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"down",
"--volumes",
]
try:
self.run_subprocess_assert_returncode(up_cmd)
finally:
self.run_subprocess_assert_returncode(down_cmd)
def test_down_with_orphans(self):
container_id, _ = self.run_subprocess_assert_returncode([
"podman",
"run",
"--rm",
"-d",
"nopush/podman-compose-test",
"dumb-init",
"/bin/busybox",
"httpd",
"-f",
"-h",
"/etc/",
"-p",
"8000",
])
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"down",
"--volumes",
"--remove-orphans",
]
self.run_subprocess_assert_returncode(down_cmd)
self.run_subprocess_assert_returncode(
[
"podman",
"container",
"exists",
container_id.decode("utf-8"),
],
1,
)

View File

@ -0,0 +1 @@

View File

@ -12,9 +12,9 @@ import unittest
from parameterized import parameterized
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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 profile_compose_file():

View File

@ -12,9 +12,9 @@ import unittest
from parameterized import parameterized
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
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 profile_compose_file():

View File

@ -1,39 +0,0 @@
# SPDX-License-Identifier: GPL-2.0
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
def compose_yaml_path():
return os.path.join(os.path.join(test_path(), "extends_w_file_subdir"), "docker-compose.yml")
class TestComposeExtendsWithFileSubdir(unittest.TestCase, RunSubprocessMixin):
def test_extends_w_file_subdir(self): # when file is Dockerfile for building the image
try:
self.run_subprocess_assert_returncode(
[
podman_compose_path(),
"-f",
compose_yaml_path(),
"up",
],
)
output, _ = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"ps",
])
self.assertIn("extends_w_file_subdir_web_1", str(output))
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"down",
])

View File

@ -1,214 +0,0 @@
# SPDX-License-Identifier: GPL-2.0
"""
test_podman_compose_up_down.py
Tests the podman compose up and down commands used to create and remove services.
"""
# pylint: disable=redefined-outer-name
import os
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
def test_exit_from(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "exit-from", "docker-compose.yaml"),
"up",
]
self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh1"], 1)
self.run_subprocess_assert_returncode(up_cmd + ["--exit-code-from", "sh2"], 2)
def test_run(self):
"""
This will test depends_on as well
"""
run_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"run",
"--rm",
"sleep",
"/bin/sh",
"-c",
"wget -q -O - http://web:8000/hosts",
]
out, _ = self.run_subprocess_assert_returncode(run_cmd)
self.assertIn(b"127.0.0.1\tlocalhost", out)
# Run it again to make sure we can run it twice. I saw an issue where a second run, with
# the container left up, would fail
run_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"run",
"--rm",
"sleep",
"/bin/sh",
"-c",
"wget -q -O - http://web:8000/hosts",
]
out, _ = self.run_subprocess_assert_returncode(run_cmd)
self.assertIn(b"127.0.0.1\tlocalhost", out)
# This leaves a container running. Not sure it's intended, but it matches docker-compose
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "deps", "docker-compose.yaml"),
"down",
]
self.run_subprocess_assert_returncode(down_cmd)
def test_up_with_ports(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"up",
"-d",
"--force-recreate",
]
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"down",
"--volumes",
]
try:
self.run_subprocess_assert_returncode(up_cmd)
finally:
self.run_subprocess_assert_returncode(down_cmd)
def test_down_with_vols(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "vol", "docker-compose.yaml"),
"up",
"-d",
]
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "vol", "docker-compose.yaml"),
"down",
"--volumes",
]
try:
self.run_subprocess_assert_returncode(["podman", "volume", "create", "my-app-data"])
self.run_subprocess_assert_returncode([
"podman",
"volume",
"create",
"actual-name-of-volume",
])
self.run_subprocess_assert_returncode(up_cmd)
self.run_subprocess(["podman", "inspect", "volume", ""])
finally:
out, _, return_code = self.run_subprocess(down_cmd)
self.run_subprocess(["podman", "volume", "rm", "my-app-data"])
self.run_subprocess(["podman", "volume", "rm", "actual-name-of-volume"])
self.assertEqual(return_code, 0)
def test_down_with_orphans(self):
container_id, _ = self.run_subprocess_assert_returncode([
"podman",
"run",
"--rm",
"-d",
"nopush/podman-compose-test",
"dumb-init",
"/bin/busybox",
"httpd",
"-f",
"-h",
"/etc/",
"-p",
"8000",
])
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "ports", "docker-compose.yml"),
"down",
"--volumes",
"--remove-orphans",
]
self.run_subprocess_assert_returncode(down_cmd)
self.run_subprocess_assert_returncode(
[
"podman",
"container",
"exists",
container_id.decode("utf-8"),
],
1,
)
def test_down_with_network(self):
try:
self.run_subprocess_assert_returncode([
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "network", "docker-compose.yml"),
"up",
"-d",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertIn("network_mystack", output.decode())
finally:
self.run_subprocess_assert_returncode([
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "network", "docker-compose.yml"),
"down",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertNotIn("network_mystack", output.decode())

View File

@ -3,6 +3,22 @@
import os
import subprocess
import time
from pathlib import Path
def base_path():
"""Returns the base path for the project"""
return Path(__file__).parent.parent.parent
def test_path():
"""Returns the path to the tests directory"""
return os.path.join(base_path(), "tests/integration")
def podman_compose_path():
"""Returns the path to the podman compose script"""
return os.path.join(base_path(), "podman_compose.py")
class RunSubprocessMixin:

View File

@ -0,0 +1 @@

View File

@ -7,8 +7,8 @@ import os
import subprocess
import unittest
from tests.integration.test_podman_compose import podman_compose_path
from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
def compose_yaml_path():

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,56 @@
# SPDX-License-Identifier: GPL-2.0
"""
test_podman_compose_up_down.py
Tests the podman compose up and down commands used to create and remove services.
"""
# pylint: disable=redefined-outer-name
import os
import unittest
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
def test_down_with_vols(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "vol", "docker-compose.yaml"),
"up",
"-d",
]
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "vol", "docker-compose.yaml"),
"down",
"--volumes",
]
try:
self.run_subprocess_assert_returncode(["podman", "volume", "create", "my-app-data"])
self.run_subprocess_assert_returncode([
"podman",
"volume",
"create",
"actual-name-of-volume",
])
self.run_subprocess_assert_returncode(up_cmd)
self.run_subprocess(["podman", "inspect", "volume", ""])
finally:
out, _, return_code = self.run_subprocess(down_cmd)
self.run_subprocess(["podman", "volume", "rm", "my-app-data"])
self.run_subprocess(["podman", "volume", "rm", "actual-name-of-volume"])
self.assertEqual(return_code, 0)