-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_aptprovider.py
More file actions
93 lines (76 loc) · 3.32 KB
/
test_aptprovider.py
File metadata and controls
93 lines (76 loc) · 3.32 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
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_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)