fix(updates): only the exit status decides apply_updates
apply_updates ran apk/opkg upgrade and returned success whatever happened, so a failed upgrade was reported as done. The command now prints its exit status after the marker get_available_updates already uses; a non-zero or missing status is a failure, named in "error". Closes #11
This commit is contained in:
1 parent
16e0fa9d5e
commit
c211ba0d9e
3 files changed
+68
-5
No files matched your search
@@ -111,3 +111,54 @@ class TestRefresh:
|
||||
result = driver.refresh_available_updates()
|
||||
|
||||
assert result == {"success": False, "output": "ERROR: network unreachable"}
|
||||
|
||||
|
||||
class TestApplyUpdates:
|
||||
"""Only the package manager's exit status decides whether an upgrade succeeded (#11)."""
|
||||
|
||||
def test_apk_upgrade_that_worked(self, driver):
|
||||
sent = _answer(
|
||||
driver, "apk", "(1/1) Upgrading dnsmasq (2.90-r4 -> 2.90-r5)\nOK\n__OWRT_RC=0\n"
|
||||
)
|
||||
|
||||
result = driver.apply_updates(["dnsmasq"])
|
||||
|
||||
assert result == {
|
||||
"success": True,
|
||||
"output": "(1/1) Upgrading dnsmasq (2.90-r4 -> 2.90-r5)\nOK",
|
||||
}
|
||||
assert sent[-1].startswith("apk upgrade dnsmasq 2>&1")
|
||||
|
||||
def test_apk_upgrade_that_failed_is_no_success(self, driver):
|
||||
_answer(
|
||||
driver,
|
||||
"apk",
|
||||
"ERROR: unable to select packages:\n nope (no such package)\n__OWRT_RC=1\n",
|
||||
)
|
||||
|
||||
result = driver.apply_updates(["nope"])
|
||||
|
||||
assert result["success"] is False
|
||||
assert "unable to select packages" in result["output"]
|
||||
assert "status 1" in result["error"]
|
||||
|
||||
def test_opkg_upgrade_that_failed_is_no_success(self, driver):
|
||||
sent = _answer(
|
||||
driver,
|
||||
"opkg",
|
||||
" * opkg_download: Failed to download\nCollected errors:\n__OWRT_RC=255\n",
|
||||
)
|
||||
|
||||
result = driver.apply_updates(["dnsmasq"])
|
||||
|
||||
assert result["success"] is False
|
||||
assert "status 255" in result["error"]
|
||||
assert sent[-1].startswith("opkg upgrade dnsmasq 2>&1")
|
||||
|
||||
def test_output_without_a_status_is_no_success(self, driver):
|
||||
_answer(driver, "opkg", "")
|
||||
|
||||
result = driver.apply_updates(["dnsmasq"])
|
||||
|
||||
assert result["success"] is False
|
||||
assert result["error"]
|
||||
Reference in new issue
Block a user