Skip to content
Snippets Groups Projects
Verified Commit 3e48d63e authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

loaders.tests: Simplify and add coverage to check_snapshot

The uncovered conditional is dead code since tests no longer run with in-memory
storage.

This adds the necessary scenario to check the no snapshot found case is
covered.

Related to T2486
parent b5caab27
Branches
Tags
No related merge requests found
......@@ -116,20 +116,7 @@ def check_snapshot(expected_snapshot, storage):
expected_branches = expected_snapshot["branches"]
snap = storage.snapshot_get(hash_to_bytes(expected_snapshot_id))
if snap is None:
# display known snapshots instead if possible
if hasattr(storage, "_snapshots"): # in-mem storage
from pprint import pprint
for snap_id, (_snap, _) in storage._snapshots.items():
snapd = _snap.to_dict()
snapd["id"] = hash_to_hex(snapd["id"])
branches = {
branch.decode("utf-8"): decode_target(target)
for branch, target in snapd["branches"].items()
}
snapd["branches"] = branches
pprint(snapd)
raise AssertionError("Snapshot is not found")
raise AssertionError(f"Snapshot {expected_snapshot_id} is not found")
branches = {
branch.decode("utf-8"): decode_target(target)
......
......@@ -243,11 +243,16 @@ def test_check_snapshot_failure():
}
unexpected_snapshot = {
"id": "2498dbf535f882bc7f9a18fb16c9ad27fda7bab7",
"id": "2498dbf535f882bc7f9a18fb16c9ad27fda7bab7", # id is correct
"branches": {
"master": {"target": hash_hex, "target_type": "release",} # wrong value
"master": {"target": hash_hex, "target_type": "release",} # wrong branch
},
}
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Differing items"):
check_snapshot(unexpected_snapshot, storage)
# snapshot id which does not exist
unexpected_snapshot["id"] = "999666f535f882bc7f9a18fb16c9ad27fda7bab7"
with pytest.raises(AssertionError, match="is not found"):
check_snapshot(unexpected_snapshot, storage)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment