提交 63f9ea12 编写于 作者: C Cleber Rosa

selftests/unit/test_utils_process.py: fix broken test logic on sudo tests

The sudo related test are currently broken in the following aspects:

 1) it doesn't require TRUE_CMD
 2) the monkey patching of find_command() produces and adverse effect,
    and makes the binary we look for ("sudo") become "true"
 3) the expected results reflect the wrong sudo binary

Let's fix those aspects, making sure the process.py library looks for
sudo only, and that it prepends that (the found sudo binary) to the
generated command.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 be5aa4c6
......@@ -125,15 +125,14 @@ class TestProcessRun(unittest.TestCase):
p = process.SubProcess(cmd='ls -l')
self.assertEqual(p.cmd, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
mock.Mock(return_value=TRUE_CMD))
mock.Mock(return_value='/bin/sudo'))
@mock.patch.object(os, 'getuid',
mock.Mock(return_value=1000))
def test_subprocess_sudo(self):
expected_command = '%s -n ls -l' % TRUE_CMD
expected_command = '/bin/sudo -n ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True)
path.find_command.assert_called_once_with('sudo')
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
......@@ -153,14 +152,13 @@ class TestProcessRun(unittest.TestCase):
p = process.SubProcess(cmd='ls -l', sudo=True)
self.assertEqual(p.cmd, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
mock.Mock(return_value=TRUE_CMD))
mock.Mock(return_value='/bin/sudo'))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_subprocess_sudo_shell(self):
expected_command = '%s -n -s ls -l' % TRUE_CMD
expected_command = '/bin/sudo -n -s ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True, shell=True)
path.find_command.assert_called_once_with('sudo')
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
......@@ -200,14 +198,13 @@ class TestProcessRun(unittest.TestCase):
p = process.run(cmd='ls -l', ignore_status=True)
self.assertEqual(p.command, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
mock.Mock(return_value=TRUE_CMD))
mock.Mock(return_value='/bin/sudo'))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo(self):
expected_command = '%s -n ls -l' % TRUE_CMD
expected_command = '/bin/sudo -n ls -l'
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
path.find_command.assert_called_once_with('sudo')
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
......@@ -227,14 +224,13 @@ class TestProcessRun(unittest.TestCase):
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
mock.Mock(return_value=TRUE_CMD))
mock.Mock(return_value='/bin/sudo'))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo_shell(self):
expected_command = '%s -n -s ls -l' % TRUE_CMD
expected_command = '/bin/sudo -n -s ls -l'
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
path.find_command.assert_called_once_with('sudo')
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册