|
| 1 | +import re |
| 2 | + |
| 3 | +import pytest |
| 4 | +import rpm |
| 5 | +from rpmlint.checks.AtomicUpdateCheck import AtomicUpdateCheck |
| 6 | +from rpmlint.filter import Filter |
| 7 | + |
| 8 | +from Testing import CONFIG, get_tested_mock_package |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture(scope='function', autouse=True) |
| 12 | +def atomiccheck(): |
| 13 | + CONFIG.info = True |
| 14 | + CONFIG.configuration['AtomicCheckGhosts'] = True |
| 15 | + output = Filter(CONFIG) |
| 16 | + test = AtomicUpdateCheck(CONFIG, output) |
| 17 | + yield output, test |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def output(atomiccheck): |
| 22 | + output, _test = atomiccheck |
| 23 | + yield output |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture |
| 27 | +def test(atomiccheck): |
| 28 | + _output, test = atomiccheck |
| 29 | + yield test |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize('package', [ |
| 33 | + get_tested_mock_package(files=('/var/lib/pipewire',)), |
| 34 | + get_tested_mock_package(files=('/opt/bin/test',)), |
| 35 | + get_tested_mock_package(files=('/usr/local/bin/test',)), |
| 36 | + get_tested_mock_package(files=('/boot/efi/test',)), |
| 37 | +]) |
| 38 | +def test_not_atomic(package, output, test): |
| 39 | + test.check(package) |
| 40 | + out = output.print_results(output.results) |
| 41 | + assert 'E: dir-or-file-outside-snapshot' in out |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize('package', [ |
| 45 | + get_tested_mock_package(files=('/etc/custom.config',)), |
| 46 | + get_tested_mock_package(files=('/usr/lib64/libc.so',)), |
| 47 | + get_tested_mock_package(files=('/usr/etc/nfs.conf',)), |
| 48 | + get_tested_mock_package(files=('/bin/test',)), |
| 49 | + get_tested_mock_package(files=('/sbin/test',)), |
| 50 | + get_tested_mock_package(files=('/lib/libc.so',)), |
| 51 | + get_tested_mock_package(files=('/lib64/libc.so',)), |
| 52 | + get_tested_mock_package(files=('/boot/grub2/grub.cfg',)), |
| 53 | +]) |
| 54 | +def test_atomic(package, output, test): |
| 55 | + test.check(package) |
| 56 | + out = output.print_results(output.results) |
| 57 | + assert 'E: dir-or-file-outside-snapshot' not in out |
| 58 | + assert 'W: ghost-outside-snapshot' not in out |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.parametrize('package', [ |
| 62 | + get_tested_mock_package(files={ |
| 63 | + '/var/lib/pipewire/ghost_file': {'metadata': {'flags': rpm.RPMFILE_GHOST}}, |
| 64 | + }), |
| 65 | +]) |
| 66 | +def test_not_atomic_ghost(package, output, test): |
| 67 | + test.check(package) |
| 68 | + out = output.print_results(output.results) |
| 69 | + assert 'W: ghost-outside-snapshot' in out |
0 commit comments