| 1 |
|
| 2 |
|
| 3 |
import argparse |
| 4 |
import unittest |
| 5 |
|
| 6 |
from podman_compose import PodmanCompose |
| 7 |
from podman_compose import compose_run_update_container_from_args |
| 8 |
|
| 9 |
|
| 10 |
class TestComposeRunUpdateContainerFromArgs(unittest.TestCase): |
| 11 |
def test_minimal(self) -> None: |
| 12 |
cnt = get_minimal_container() |
| 13 |
compose = get_minimal_compose() |
| 14 |
args = get_minimal_args() |
| 15 |
|
| 16 |
compose_run_update_container_from_args(compose, cnt, args) |
| 17 |
|
| 18 |
expected_cnt = {"name": "default_name", "tty": True} |
| 19 |
self.assertEqual(cnt, expected_cnt) |
| 20 |
|
| 21 |
def test_additional_env_value_equals(self) -> None: |
| 22 |
cnt = get_minimal_container() |
| 23 |
compose = get_minimal_compose() |
| 24 |
args = get_minimal_args() |
| 25 |
args.env = ["key=valuepart1=valuepart2"] |
| 26 |
|
| 27 |
compose_run_update_container_from_args(compose, cnt, args) |
| 28 |
|
| 29 |
expected_cnt = { |
| 30 |
"environment": { |
| 31 |
"key": "valuepart1=valuepart2", |
| 32 |
}, |
| 33 |
"name": "default_name", |
| 34 |
"tty": True, |
| 35 |
} |
| 36 |
self.assertEqual(cnt, expected_cnt) |
| 37 |
|
| 38 |
def test_publish_ports(self) -> None: |
| 39 |
cnt = get_minimal_container() |
| 40 |
compose = get_minimal_compose() |
| 41 |
args = get_minimal_args() |
| 42 |
args.publish = ["1111", "2222:2222"] |
| 43 |
|
| 44 |
compose_run_update_container_from_args(compose, cnt, args) |
| 45 |
|
| 46 |
expected_cnt = { |
| 47 |
"name": "default_name", |
| 48 |
"ports": ["1111", "2222:2222"], |
| 49 |
"tty": True, |
| 50 |
} |
| 51 |
self.assertEqual(cnt, expected_cnt) |
| 52 |
|
| 53 |
|
| 54 |
def get_minimal_container() -> dict: |
| 55 |
return {} |
| 56 |
|
| 57 |
|
| 58 |
def get_minimal_compose() -> PodmanCompose: |
| 59 |
compose = PodmanCompose() |
| 60 |
compose.project_name = "test_project" |
| 61 |
return compose |
| 62 |
|
| 63 |
|
| 64 |
def get_minimal_args() -> argparse.Namespace: |
| 65 |
return argparse.Namespace( |
| 66 |
T=None, |
| 67 |
cnt_command=None, |
| 68 |
entrypoint=None, |
| 69 |
env=None, |
| 70 |
name="default_name", |
| 71 |
rm=None, |
| 72 |
service="test_service", |
| 73 |
publish=None, |
| 74 |
service_ports=None, |
| 75 |
user=None, |
| 76 |
volume=None, |
| 77 |
workdir=None, |
| 78 |
) |