mirror of
https://github.com/containers/podman-compose.git
synced 2025-02-09 06:49:18 +01:00
Split exec args parsing into new function and add unit tests for it
Signed-off-by: Ari Pollak <ajp@aripollak.com>
This commit is contained in:
parent
4c270b9116
commit
c4fa8f7a16
@ -2502,6 +2502,12 @@ async def compose_exec(compose, args):
|
||||
container_names = compose.container_names_by_service[args.service]
|
||||
container_name = container_names[args.index - 1]
|
||||
cnt = compose.container_by_name[container_name]
|
||||
podman_args = compose_exec_args(cnt, container_name, args)
|
||||
p = await compose.podman.run([], "exec", podman_args)
|
||||
sys.exit(p)
|
||||
|
||||
|
||||
def compose_exec_args(cnt, container_name, args):
|
||||
podman_args = ["--interactive"]
|
||||
if args.privileged:
|
||||
podman_args += ["--privileged"]
|
||||
@ -2522,8 +2528,7 @@ async def compose_exec(compose, args):
|
||||
podman_args += [container_name]
|
||||
if args.cnt_command is not None and len(args.cnt_command) > 0:
|
||||
podman_args += args.cnt_command
|
||||
p = await compose.podman.run([], "exec", podman_args)
|
||||
sys.exit(p)
|
||||
return podman_args
|
||||
|
||||
|
||||
async def transfer_service_status(compose, args, action):
|
||||
|
46
pytests/test_compose_exec_args.py
Normal file
46
pytests/test_compose_exec_args.py
Normal file
@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
import argparse
|
||||
import unittest
|
||||
|
||||
from podman_compose import compose_exec_args
|
||||
|
||||
|
||||
class TestExecArgs(unittest.TestCase):
|
||||
def test_minimal(self):
|
||||
cnt = get_minimal_container()
|
||||
args = get_minimal_args()
|
||||
|
||||
result = compose_exec_args(cnt, "container_name", args)
|
||||
expected = ["--interactive", "--tty", "container_name"]
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_additional_env_value_equals(self):
|
||||
cnt = get_minimal_container()
|
||||
args = get_minimal_args()
|
||||
args.env = ["key=valuepart1=valuepart2"]
|
||||
|
||||
result = compose_exec_args(cnt, "container_name", args)
|
||||
expected = [
|
||||
"--interactive",
|
||||
"--tty",
|
||||
"--env",
|
||||
"key=valuepart1=valuepart2",
|
||||
"container_name",
|
||||
]
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
|
||||
def get_minimal_container():
|
||||
return {}
|
||||
|
||||
|
||||
def get_minimal_args():
|
||||
return argparse.Namespace(
|
||||
T=None,
|
||||
cnt_command=None,
|
||||
env=None,
|
||||
privileged=None,
|
||||
user=None,
|
||||
workdir=None,
|
||||
)
|
Loading…
Reference in New Issue
Block a user