|
11 | 11 | from unittest import mock |
12 | 12 | import tempfile |
13 | 13 | import json |
| 14 | +import platform |
14 | 15 |
|
15 | 16 | from azure.cli.core.util import \ |
16 | 17 | (get_file_json, truncate_text, shell_safe_json_parse, b64_to_hex, hash_string, random_string, |
17 | 18 | open_page_in_browser, can_launch_browser, handle_exception, ConfiguredDefaultSetter, send_raw_request, |
18 | 19 | should_disable_connection_verify, parse_proxy_resource_id, get_az_user_agent, get_az_rest_user_agent, |
19 | | - _get_parent_proc_name, is_wsl) |
| 20 | + _get_parent_proc_name, is_wsl, run_cmd) |
20 | 21 | from azure.cli.core.mock import DummyCli |
21 | 22 |
|
22 | 23 |
|
@@ -421,6 +422,26 @@ def test_get_parent_proc_name(self, mock_process_type): |
421 | 422 | parent2.name.return_value = "bash" |
422 | 423 | self.assertEqual(_get_parent_proc_name(), "pwsh") |
423 | 424 |
|
| 425 | + def test_cli_run_cmd(self): |
| 426 | + cmd = ["echo", "abc"] |
| 427 | + if platform.system().lower() == "windows": |
| 428 | + cmd = ["cmd.exe", "/c"] + cmd |
| 429 | + output = run_cmd(cmd, capture_output=True) |
| 430 | + self.assertEqual(output.returncode, 0, "error when run cmd in shell") |
| 431 | + self.assertEqual(output.stdout.decode("utf8").strip(), "abc", "unexpected output when run cmd") |
| 432 | + |
| 433 | + output = run_cmd(cmd, capture_output=True, encoding="utf8") |
| 434 | + self.assertEqual(output.returncode, 0, "error when run cmd in shell") |
| 435 | + self.assertEqual(output.stdout.strip(), "abc", "unexpected output when run cmd") |
| 436 | + |
| 437 | + def test_run_cmd_arg_error(self): |
| 438 | + cmd = "echo abc" |
| 439 | + if platform.system().lower() == "windows": |
| 440 | + cmd = "cmd.exe /c " + cmd |
| 441 | + from azure.cli.core.azclierror import ArgumentUsageError |
| 442 | + with self.assertRaises(ArgumentUsageError): |
| 443 | + run_cmd(cmd, check=True) |
| 444 | + |
424 | 445 |
|
425 | 446 | class TestBase64ToHex(unittest.TestCase): |
426 | 447 |
|
|
0 commit comments