Debian Codegraph @

test/unit/package_manager/apk_test.py

raw
1 from unittest.mock import (
2 patch, Mock
3 )
4 from pytest import (
5 fixture, raises
6 )
7
8 from kiwi.package_manager.apk import PackageManagerApk
9
10 from kiwi.exceptions import KiwiBootStrapPhaseFailed
11
12
13 class TestPackageManagerApk:
14 @fixture(autouse=True)
15 def inject_fixtures(self, caplog):
16 self._caplog = caplog
17
18 def setup(self):
19 repository = Mock()
20 repository.root_dir = '/root-dir'
21
22 repository.runtime_config = Mock(
23 return_value={
24 'bootstrap_repo': 'https://some',
25 'command_env': ['env']
26 }
27 )
28 self.manager = PackageManagerApk(repository)
29
30 def setup_method(self, cls):
31 self.setup()
32
33 def test_request_package(self):
34 self.manager.request_package('name')
35 assert self.manager.package_requests == ['name']
36
37 def test_request_collection(self):
38 self.manager.request_collection('name')
39 assert self.manager.collection_requests == []
40 assert self.manager.package_requests == ['name']
41
42 def test_request_product(self):
43 self.manager.request_product('name')
44 assert self.manager.product_requests == []
45
46 def test_request_package_exclusion(self):
47 self.manager.request_package_exclusion('name')
48 assert self.manager.exclude_requests == ['name']
49
50 def test_setup_repository_modules(self):
51 self.manager.setup_repository_modules({})
52
53 def test_process_install_requests_bootstrap_raises(self):
54 self.manager.bootstrap_repo = None
55 with raises(KiwiBootStrapPhaseFailed):
56 self.manager.process_install_requests_bootstrap()
57
58 @patch('kiwi.command.Command.call')
59 def test_process_install_requests_bootstrap_default(self, mock_call):
60 self.manager.process_install_requests_bootstrap()
61 mock_call.assert_called_once_with(
62 [
63 'apk', '--root', '/root-dir', '-X', 'https://some',
64 '-U', '--allow-untrusted', '--initdb', 'add',
65 'alpine-base',
66 ], ['env']
67 )
68
69 @patch('kiwi.command.Command.call')
70 def test_process_install_requests_bootstrap(self, mock_call):
71 self.manager.request_package('vim')
72 self.manager.request_collection('collection')
73 self.manager.process_install_requests_bootstrap()
74 mock_call.assert_called_once_with(
75 [
76 'apk', '--root', '/root-dir', '-X', 'https://some',
77 '-U', '--allow-untrusted', '--initdb', 'add',
78 'vim', 'collection'
79 ], ['env']
80 )
81
82 @patch('kiwi.command.Command.call')
83 @patch('kiwi.command.Command.run')
84 def test_process_install_requests(self, mock_run, mock_call):
85 self.manager.request_package('vim')
86 self.manager.request_collection('collection')
87 self.manager.request_package_exclusion('skipme')
88 self.manager.process_install_requests()
89 mock_run.assert_called_once_with(
90 ['chroot', '/root-dir', 'apk', 'update']
91 )
92 mock_call.assert_called_once_with(
93 ['chroot', '/root-dir', 'apk', 'add', 'vim', 'collection'],
94 ['env']
95 )
96
97 @patch('kiwi.command.Command.call')
98 @patch('kiwi.command.Command.run')
99 def test_process_delete_requests(self, mock_run, mock_call):
100 self.manager.request_package('vim')
101 self.manager.process_delete_requests()
102 mock_run.assert_called_once_with(
103 ['chroot', '/root-dir', 'apk', 'update']
104 )
105 mock_call.assert_called_once_with(
106 ['chroot', '/root-dir', 'apk', 'del', 'vim'],
107 ['env']
108 )
109
110 def test_process_only_required(self):
111 self.manager.process_only_required()
112 assert self.manager.custom_args == []
113
114 def test_process_plus_recommended(self):
115 self.manager.process_plus_recommended()
116 assert self.manager.custom_args == []
117
118 @patch('kiwi.command.Command.call')
119 @patch('kiwi.command.Command.run')
120 def test_update(self, mock_run, mock_call):
121 self.manager.update()
122 mock_run.assert_called_once_with(
123 ['chroot', '/root-dir', 'apk', 'update']
124 )
125 mock_call.assert_called_once_with(
126 ['chroot', '/root-dir', 'apk', 'upgrade'],
127 ['env']
128 )
129
130 def test_match_package_installed(self):
131 assert self.manager.match_package_installed('foo', ' Installing foo')
132
133 def test_match_package_deleted(self):
134 assert self.manager.match_package_deleted('foo', ' Removing foo')