test Single.shim_cmd()
(opts, target, tmp_path)
| 553 | |
| 554 | |
| 555 | def test_shim_cmd(opts, target, tmp_path): |
| 556 | """ |
| 557 | test Single.shim_cmd() |
| 558 | """ |
| 559 | single = ssh.Single( |
| 560 | opts, |
| 561 | opts["argv"], |
| 562 | "localhost", |
| 563 | mods={}, |
| 564 | fsclient=None, |
| 565 | thin=salt.utils.thin.thin_path(opts["cachedir"]), |
| 566 | mine=False, |
| 567 | winrm=False, |
| 568 | tty=True, |
| 569 | **target, |
| 570 | ) |
| 571 | |
| 572 | exp_ret = ("Success", "", 0) |
| 573 | mock_cmd = MagicMock(return_value=exp_ret) |
| 574 | patch_cmd = patch("salt.client.ssh.shell.Shell.exec_cmd", mock_cmd) |
| 575 | patch_send = patch("salt.client.ssh.shell.Shell.send", return_value=("", "", 0)) |
| 576 | patch_rand = patch("os.urandom", return_value=b"5\xd9l\xca\xc2\xff") |
| 577 | tmp_file = tmp_path / "tmp_file" |
| 578 | mock_tmp = MagicMock() |
| 579 | patch_tmp = patch("tempfile.NamedTemporaryFile", mock_tmp) |
| 580 | mock_tmp.return_value.__enter__.return_value.name = tmp_file |
| 581 | |
| 582 | with patch_cmd, patch_tmp, patch_send: |
| 583 | ret = single.shim_cmd(cmd_str="echo test") |
| 584 | assert ret == exp_ret |
| 585 | assert [ |
| 586 | call(f"/bin/sh '.{tmp_file.name}'"), |
| 587 | call(f"rm '.{tmp_file.name}'"), |
| 588 | ] == mock_cmd.call_args_list |
| 589 | |
| 590 | |
| 591 | def test_shim_cmd_copy_fails(opts, target, caplog): |