File: test_normalize_service.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 (74 lines) | stat: -rw-r--r-- 2,874 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
# SPDX-License-Identifier: GPL-2.0
import unittest
from typing import Any
from typing import Union

from parameterized import parameterized

from podman_compose import normalize_service


class TestNormalizeService(unittest.TestCase):
    @parameterized.expand([
        ({"test": "test"}, {"test": "test"}),
        ({"build": "."}, {"build": {"context": "."}}),
        ({"build": "./dir-1"}, {"build": {"context": "./dir-1"}}),
        ({"build": {"context": "./dir-1"}}, {"build": {"context": "./dir-1"}}),
        (
            {"build": {"dockerfile": "dockerfile-1"}},
            {"build": {"dockerfile": "dockerfile-1"}},
        ),
        (
            {"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
            {"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
        ),
        (
            {"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
            {"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
        ),
        (
            {"build": {"additional_contexts": {"ctx": "../ctx", "ctx2": "../ctx2"}}},
            {"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
        ),
    ])
    def test_simple(self, input: dict[str, Any], expected: dict[str, Any]) -> None:
        self.assertEqual(normalize_service(input), expected)

    @parameterized.expand([
        ({"test": "test"}, {"test": "test"}),
        ({"build": "."}, {"build": {"context": "./sub_dir/."}}),
        ({"build": "./dir-1"}, {"build": {"context": "./sub_dir/dir-1"}}),
        ({"build": {"context": "./dir-1"}}, {"build": {"context": "./sub_dir/dir-1"}}),
        (
            {"build": {"dockerfile": "dockerfile-1"}},
            {"build": {"context": "./sub_dir", "dockerfile": "dockerfile-1"}},
        ),
        (
            {"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
            {"build": {"context": "./sub_dir/dir-1", "dockerfile": "dockerfile-1"}},
        ),
    ])
    def test_normalize_service_with_sub_dir(
        self, input: dict[str, Any], expected: dict[str, Any]
    ) -> None:
        self.assertEqual(normalize_service(input, sub_dir="./sub_dir"), expected)

    @parameterized.expand([
        ([], []),
        (["sh"], ["sh"]),
        (["sh", "-c", "date"], ["sh", "-c", "date"]),
        ("sh", ["sh"]),
        ("sleep infinity", ["sleep", "infinity"]),
        (
            "bash -c 'sleep infinity'",
            ["bash", "-c", "sleep infinity"],
        ),
    ])
    def test_command_like(self, input: Union[list[str], str], expected: list[str]) -> None:
        for key in ['command', 'entrypoint']:
            input_service = {}
            input_service[key] = input

            expected_service = {}
            expected_service[key] = expected
            self.assertEqual(normalize_service(input_service), expected_service)