Пример #1
0
def test_execute_command_not_found(mocker):
    mocker.patch(
        "aws_gate.utils.subprocess.run",
        side_effect=OSError(errno.ENOENT, os.strerror(errno.ENOENT)),
    )
    with pytest.raises(ValueError):
        execute("/usr/bin/ls", ["-l"])
Пример #2
0
def test_execute_environment(mocker):
    mock_output = mocker.MagicMock(stdout=b"output")
    m = mocker.patch("aws_gate.utils.subprocess.run", return_value=mock_output)

    execute("ls", ["-l"])

    assert m.call_args_list[0][1]["env"] is not None
    assert DEFAULT_GATE_BIN_PATH in m.call_args_list[0][1]["env"]["PATH"]
Пример #3
0
def test_execute_command_exited_with_nonzero_rc(mocker):
    mock = mocker.patch(
        "aws_gate.utils.subprocess.run",
        side_effect=subprocess.CalledProcessError(returncode=1, cmd="error"),
    )
    execute("/usr/bin/ls", ["-l"])

    assert mock.called
Пример #4
0
    def open(self):
        self._ssh_cmd = self._build_ssh_command()

        return execute(self._ssh_cmd[0], self._ssh_cmd[1:])
Пример #5
0
def test_execute(mocker, cmd, args):
    mock_output = mocker.MagicMock(stdout=b"output")
    mocker.patch("aws_gate.utils.subprocess.run", return_value=mock_output)

    assert execute(cmd, args) == "output"
Пример #6
0
def _check_plugin_version(path=PLUGIN_INSTALL_PATH):
    return execute(path, ["--version"], capture_output=True)
Пример #7
0
 def test_execute_command_not_found(self):
     with patch('aws_gate.utils.subprocess.run',
                side_effect=OSError(errno.ENOENT, os.strerror(errno.ENOENT))):
         with self.assertRaises(ValueError):
             execute('/usr/bin/ls', ['-l'])
Пример #8
0
    def test_execute_command_exited_with_nonzero_rc(self):
        with patch('aws_gate.utils.subprocess.run',
                   side_effect=subprocess.CalledProcessError(returncode=1, cmd='error')) as mock:
            execute('/usr/bin/ls', ['-l'])

            self.assertTrue(mock.called)
Пример #9
0
    def test_execute(self, cmd, args):
        mock_output = MagicMock(stdout=b'output')

        with patch('aws_gate.utils.subprocess.run', return_value=mock_output):
            self.assertEqual(execute(cmd, args), 'output')
Пример #10
0
def _check_plugin_version(path=PLUGIN_INSTALL_PATH):
    return execute(path, ["--version"], stdout=PIPE, stderr=PIPE)