| 1 |
from unittest.mock import patch, call |
| 2 |
from pytest import ( |
| 3 |
raises, fixture |
| 4 |
) |
| 5 |
import unittest.mock as mock |
| 6 |
|
| 7 |
from kiwi.package_manager.pacman import PackageManagerPacman |
| 8 |
|
| 9 |
from kiwi.exceptions import KiwiRequestError |
| 10 |
|
| 11 |
|
| 12 |
class TestPackageManagerPacman: |
| 13 |
@fixture(autouse=True) |
| 14 |
def inject_fixtures(self, caplog): |
| 15 |
self._caplog = caplog |
| 16 |
|
| 17 |
def setup(self): |
| 18 |
repository = mock.Mock() |
| 19 |
repository.root_dir = '/root-dir' |
| 20 |
|
| 21 |
repository.runtime_config = mock.Mock( |
| 22 |
return_value={ |
| 23 |
'pacman_args': [ |
| 24 |
'--config', '/root-dir/pacman.conf', '-y', '--noconfirm' |
| 25 |
], |
| 26 |
'command_env': ['env'] |
| 27 |
} |
| 28 |
) |
| 29 |
self.manager = PackageManagerPacman(repository) |
| 30 |
|
| 31 |
def setup_method(self, cls): |
| 32 |
self.setup() |
| 33 |
|
| 34 |
def test_request_package(self): |
| 35 |
self.manager.request_package('name') |
| 36 |
assert self.manager.package_requests == ['name'] |
| 37 |
|
| 38 |
def test_request_collection(self): |
| 39 |
self.manager.request_collection('name') |
| 40 |
assert self.manager.collection_requests == [] |
| 41 |
assert self.manager.package_requests == ['name'] |
| 42 |
|
| 43 |
def test_request_product(self): |
| 44 |
self.manager.request_product('name') |
| 45 |
assert self.manager.product_requests == [] |
| 46 |
|
| 47 |
def test_request_package_exclusion(self): |
| 48 |
self.manager.request_package_exclusion('name') |
| 49 |
assert self.manager.exclude_requests == ['name'] |
| 50 |
|
| 51 |
def test_setup_repository_modules(self): |
| 52 |
self.manager.setup_repository_modules({}) |
| 53 |
|
| 54 |
@patch('kiwi.command.Command.call') |
| 55 |
@patch('kiwi.command.Command.run') |
| 56 |
def test_process_install_requests_bootstrap(self, mock_run, mock_call): |
| 57 |
self.manager.request_package('vim') |
| 58 |
self.manager.request_collection('collection') |
| 59 |
self.manager.process_install_requests_bootstrap() |
| 60 |
mock_run.call_args_list == [ |
| 61 |
call(['rm', '-r', '-f', '/root-dir/var/run']), |
| 62 |
call([ |
| 63 |
'pacman', '--config', '/root-dir/pacman.conf', '-y', |
| 64 |
'--noconfirm', '--needed', '--root', '/root-dir', '-Sy' |
| 65 |
]) |
| 66 |
] |
| 67 |
mock_call.assert_called_once_with( |
| 68 |
[ |
| 69 |
'pacman', '--config', '/root-dir/pacman.conf', |
| 70 |
'-y', '--noconfirm', '--root', '/root-dir', '-S', |
| 71 |
'--needed', '--overwrite', '/root-dir/var/run', |
| 72 |
'vim', 'collection' |
| 73 |
], ['env'] |
| 74 |
) |
| 75 |
|
| 76 |
@patch('kiwi.command.Command.call') |
| 77 |
def test_process_install_requests(self, mock_call): |
| 78 |
self.manager.request_package('vim') |
| 79 |
self.manager.request_collection('collection') |
| 80 |
self.manager.request_package_exclusion('skipme') |
| 81 |
self.manager.process_install_requests() |
| 82 |
mock_call.assert_called_once_with( |
| 83 |
[ |
| 84 |
'chroot', '/root-dir', 'pacman', '--config', |
| 85 |
'/pacman.conf', '-y', '--noconfirm', '-S', |
| 86 |
'--needed', 'vim', 'collection' |
| 87 |
], ['env'] |
| 88 |
) |
| 89 |
|
| 90 |
@patch('kiwi.command.Command.call') |
| 91 |
@patch('kiwi.command.Command.run') |
| 92 |
def test_process_delete_requests_force(self, mock_run, mock_call): |
| 93 |
self.manager.request_package('vim') |
| 94 |
self.manager.process_delete_requests(True) |
| 95 |
mock_call.assert_called_once_with( |
| 96 |
[ |
| 97 |
'chroot', '/root-dir', 'pacman', '--config', '/pacman.conf', |
| 98 |
'-y', '--noconfirm', '-Rdd', 'vim' |
| 99 |
], ['env'] |
| 100 |
) |
| 101 |
|
| 102 |
@patch('kiwi.command.Command.call') |
| 103 |
@patch('kiwi.command.Command.run') |
| 104 |
def test_process_delete_requests_no_force(self, mock_run, mock_call): |
| 105 |
self.manager.request_package('vim') |
| 106 |
self.manager.process_delete_requests() |
| 107 |
mock_call.assert_called_once_with( |
| 108 |
[ |
| 109 |
'chroot', '/root-dir', 'pacman', '--config', '/pacman.conf', |
| 110 |
'-y', '--noconfirm', '-Rs', 'vim' |
| 111 |
], ['env'] |
| 112 |
) |
| 113 |
|
| 114 |
@patch('kiwi.command.Command.run') |
| 115 |
@patch('kiwi.command.Command.call') |
| 116 |
def test_process_delete_requests_package_missing( |
| 117 |
self, mock_call, mock_run |
| 118 |
): |
| 119 |
mock_run.side_effect = Exception |
| 120 |
self.manager.request_package('vim') |
| 121 |
with raises(KiwiRequestError): |
| 122 |
self.manager.process_delete_requests() |
| 123 |
mock_run.assert_called_once_with( |
| 124 |
['chroot', '/root-dir', 'pacman', '-Qi', 'vim'] |
| 125 |
) |
| 126 |
|
| 127 |
def test_process_only_required(self): |
| 128 |
self.manager.process_only_required() |
| 129 |
assert self.manager.custom_args == [] |
| 130 |
|
| 131 |
def test_process_plus_recommended(self): |
| 132 |
self.manager.process_plus_recommended() |
| 133 |
assert self.manager.custom_args == [] |
| 134 |
|
| 135 |
@patch('kiwi.command.Command.call') |
| 136 |
def test_update(self, mock_call): |
| 137 |
self.manager.update() |
| 138 |
mock_call.assert_called_once_with( |
| 139 |
[ |
| 140 |
'chroot', '/root-dir', 'pacman', '--config', '/pacman.conf', |
| 141 |
'-y', '--noconfirm', '-Su' |
| 142 |
], ['env'] |
| 143 |
) |
| 144 |
|
| 145 |
def test_match_package_installed(self): |
| 146 |
assert self.manager.match_package_installed('foo', ' installing foo') |
| 147 |
|
| 148 |
def test_match_package_deleted(self): |
| 149 |
assert self.manager.match_package_deleted('foo', ' removing foo') |