Skip to content

Commit

Permalink
Merge pull request #49 from lsst-sqre/tickets/DM-28120
Browse files Browse the repository at this point in the history
[DM-28120] Fix parsing of cachemachine entries without hashes
  • Loading branch information
rra authored Apr 21, 2021
2 parents 9be53f6 + 13c286e commit 17756ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit 17756ce

Please sign in to comment.