test: add image download/checksum tests

This commit is contained in:
Brad Stein 2026-01-11 09:45:26 -03:00
parent f22f8cfe30
commit 3e950a4aca

30
tests/test_image.py Normal file
View File

@ -0,0 +1,30 @@
import hashlib
from pathlib import Path
from metis.pkg import image
def test_download_file_url(tmp_path):
src = tmp_path / "src.bin"
src.write_bytes(b"hello")
dest = tmp_path / "dest.bin"
image.Download(f"file://{src}", dest)
assert dest.read_bytes() == b"hello"
def test_checksum_ok(tmp_path):
f = tmp_path / "file.bin"
f.write_bytes(b"abc")
checksum = "sha256:" + hashlib.sha256(b"abc").hexdigest()
image.VerifyChecksum(f, checksum)
def test_checksum_bad(tmp_path):
f = tmp_path / "file.bin"
f.write_bytes(b"abc")
checksum = "sha256:deadbeef"
try:
image.VerifyChecksum(f, checksum)
except Exception:
return
raise AssertionError("expected checksum failure")