File: test_compose_run_update_container_from_args.py

package info (click to toggle)
podman-compose 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,004 kB
  • sloc: python: 10,946; sh: 107; javascript: 48; makefile: 13
file content (78 lines) | stat: -rw-r--r-- 2,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# SPDX-License-Identifier: GPL-2.0

import argparse
import unittest

from podman_compose import PodmanCompose
from podman_compose import compose_run_update_container_from_args


class TestComposeRunUpdateContainerFromArgs(unittest.TestCase):
    def test_minimal(self) -> None:
        cnt = get_minimal_container()
        compose = get_minimal_compose()
        args = get_minimal_args()

        compose_run_update_container_from_args(compose, cnt, args)

        expected_cnt = {"name": "default_name", "tty": True}
        self.assertEqual(cnt, expected_cnt)

    def test_additional_env_value_equals(self) -> None:
        cnt = get_minimal_container()
        compose = get_minimal_compose()
        args = get_minimal_args()
        args.env = ["key=valuepart1=valuepart2"]

        compose_run_update_container_from_args(compose, cnt, args)

        expected_cnt = {
            "environment": {
                "key": "valuepart1=valuepart2",
            },
            "name": "default_name",
            "tty": True,
        }
        self.assertEqual(cnt, expected_cnt)

    def test_publish_ports(self) -> None:
        cnt = get_minimal_container()
        compose = get_minimal_compose()
        args = get_minimal_args()
        args.publish = ["1111", "2222:2222"]

        compose_run_update_container_from_args(compose, cnt, args)

        expected_cnt = {
            "name": "default_name",
            "ports": ["1111", "2222:2222"],
            "tty": True,
        }
        self.assertEqual(cnt, expected_cnt)


def get_minimal_container() -> dict:
    return {}


def get_minimal_compose() -> PodmanCompose:
    compose = PodmanCompose()
    compose.project_name = "test_project"
    return compose


def get_minimal_args() -> argparse.Namespace:
    return argparse.Namespace(
        T=None,
        cnt_command=None,
        entrypoint=None,
        env=None,
        name="default_name",
        rm=None,
        service="test_service",
        publish=None,
        service_ports=None,
        user=None,
        volume=None,
        workdir=None,
    )