diff --git a/tests/test_image.py b/tests/test_image.py new file mode 100644 index 0000000..e8d7384 --- /dev/null +++ b/tests/test_image.py @@ -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")