Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DM-28120] Fix parsing of cachemachine entries without hashes #49

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nublado2/imageinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def from_cachemachine_entry(cls, entry: CachemachineEntry) -> "ImageInfo":
return cls(
reference=entry["image_url"],
display_name=entry["name"],
digest=(entry["image_hash"] or ""),
digest=entry.get("image_hash", ""),
)

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions tests/imageinfo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def test_creation_from_cachemachine_entry() -> None:
assert img.digest == TEST_DIGEST


def test_creation_without_hash() -> None:
"""Create from a dict like we'd get from cachemachine but with no hash."""
entry = dict(**TEST_ENTRY)
del entry["image_hash"]
img = ImageInfo.from_cachemachine_entry(entry)
assert img.reference == TEST_REF
assert img.display_name == TEST_DISPLAY_NAME
assert img.digest == ""


def test_roundtrip() -> None:
"""Create an object from a cachemachine entry, get its packed string,
create a new object from that, and test that the fields are the same."""
Expand Down