Skip to content

Commit

Permalink
test: Fix test_extract_fail when running as root
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Sep 4, 2024
1 parent cd5f890 commit bb7c220
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/test_pkg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
import rpm
import os
import subprocess
import unittest.mock as mock

import pytest
import rpm
from rpmlint.pkg import parse_deps, rangeCompare

from Testing import get_tested_package
Expand All @@ -28,11 +30,20 @@ def test_range_compare():

@pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess'])
def test_extract_fail(package, tmp_path):
with mock.patch("shutil.which") as mock_which:
"""
Check that rpm2cpio fails to extract this package because it has no
permissions to some files.
"""

# Root can extract the package, so nothing to check
if os.getuid() == 0:
return

with mock.patch('shutil.which') as mock_which:
mock_which.return_value = None
# the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission
with pytest.raises(subprocess.CalledProcessError) as exc:
get_tested_package(package, tmp_path)
mock_which.assert_called_once_with("rpm2archive")
mock_which.assert_called_once_with('rpm2archive')
# check that it was rpm2cpio what failed
assert exc.match(r"rpm2cpio .*")
assert exc.match(r'rpm2cpio .*')

0 comments on commit bb7c220

Please sign in to comment.