-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_aptprovider.py
More file actions
111 lines (93 loc) · 4.28 KB
/
test_aptprovider.py
File metadata and controls
111 lines (93 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import sys
import logging
import pytest
from abxpkg import AptProvider, Binary
@pytest.mark.skipif("darwin" in sys.platform, reason="apt is not available on macOS")
@pytest.mark.root_required
class TestAptProvider:
def test_provider_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("apt-get")
provider = AptProvider(postinstall_scripts=True, min_release_age=0)
test_machine.exercise_provider_lifecycle(
provider,
bin_name=test_machine.pick_missing_apt_package(),
)
def test_unsupported_security_controls_warn_and_continue(
self,
test_machine,
caplog,
):
test_machine.require_tool("apt-get")
package = test_machine.pick_missing_apt_package()
with caplog.at_level(logging.WARNING, logger="abxpkg.binprovider"):
installed = AptProvider().install(
package,
postinstall_scripts=False,
min_release_age=1,
)
test_machine.assert_shallow_binary_loaded(installed)
assert "ignoring unsupported min_release_age=1" in caplog.text
assert "ignoring unsupported postinstall_scripts=False" in caplog.text
caplog.clear()
binary = Binary(
name=test_machine.pick_missing_apt_package(),
binproviders=[AptProvider()],
postinstall_scripts=False,
min_release_age=1,
)
with caplog.at_level(logging.WARNING, logger="abxpkg.binprovider"):
installed = binary.install()
test_machine.assert_shallow_binary_loaded(installed)
assert "ignoring unsupported min_release_age=1" in caplog.text
assert "ignoring unsupported postinstall_scripts=False" in caplog.text
def test_binary_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("apt-get")
binary = Binary(
name=test_machine.pick_missing_apt_package(),
binproviders=[
AptProvider(postinstall_scripts=True, min_release_age=0),
],
postinstall_scripts=True,
min_release_age=0,
)
test_machine.exercise_binary_lifecycle(binary)
def test_provider_dry_run_does_not_install_package(self, test_machine):
test_machine.require_tool("apt-get")
provider = AptProvider(postinstall_scripts=True, min_release_age=0)
test_machine.exercise_provider_dry_run(
provider,
bin_name=test_machine.pick_missing_apt_package(),
)
def test_search_finds_real_apt_package_and_install_works(self, test_machine):
test_machine.require_tool("apt-get")
provider = AptProvider(postinstall_scripts=True, min_release_age=0)
results = provider.search("wget")
assert results, "apt-cache search wget should return matches"
names = [r.name for r in results]
assert "wget" in names
wget_match = next(r for r in results if r.name == "wget")
assert wget_match.overrides == {"apt": {"install_args": ["wget"]}}
# The returned Binary is non-loaded — it has no abspath/version yet.
assert wget_match.loaded_abspath is None
assert wget_match.loaded_version is None
# ...but installing it must produce a real, valid binary on disk.
provider.uninstall("wget", quiet=True, no_cache=True)
installed = wget_match.install()
test_machine.assert_shallow_binary_loaded(installed)
assert installed.name == "wget"
def test_helper_install_args_used_by_native_apt_backend(self, test_machine):
test_machine.require_tool("apt-get")
primary = test_machine.pick_missing_apt_package()
extra = "jq" if primary != "jq" else "tree"
provider = AptProvider(
postinstall_scripts=True,
min_release_age=0,
).get_provider_with_overrides(
overrides={primary: {"install_args": [primary, extra]}},
)
for pkg in (primary, extra):
provider.uninstall(pkg, quiet=True, no_cache=True)
provider.install(primary, no_cache=True)
assert provider.load(extra, quiet=True, no_cache=True) is not None
provider.uninstall(primary, no_cache=True)
provider.uninstall(extra, quiet=True, no_cache=True)