58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPT = ROOT / "tools/checks/runtime-image-smoke.py"
|
|
SPEC = importlib.util.spec_from_file_location("runtime_image_smoke", SCRIPT)
|
|
assert SPEC is not None and SPEC.loader is not None
|
|
MODULE = importlib.util.module_from_spec(SPEC)
|
|
sys.modules[SPEC.name] = MODULE
|
|
SPEC.loader.exec_module(MODULE)
|
|
|
|
|
|
class RuntimeImageSmokeTests(unittest.TestCase):
|
|
def test_selects_the_exact_platform_digest(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-runtime-smoke-") as value:
|
|
path = Path(value) / "metadata.json"
|
|
path.write_text(
|
|
json.dumps(
|
|
{
|
|
"index": "registry.example/api@sha256:" + "a" * 64,
|
|
"platforms": {
|
|
"linux/amd64": "registry.example/api@sha256:" + "1" * 64,
|
|
"linux/arm64": "registry.example/api@sha256:" + "2" * 64,
|
|
},
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
self.assertEqual(
|
|
"registry.example/api@sha256:" + "2" * 64,
|
|
MODULE.platform_image(path, "linux/arm64", "API"),
|
|
)
|
|
|
|
def test_rejects_mutable_or_missing_platform_images(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-runtime-smoke-") as value:
|
|
path = Path(value) / "metadata.json"
|
|
path.write_text(
|
|
json.dumps({"platforms": {"linux/amd64": "registry.example/api:latest"}}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with self.assertRaisesRegex(MODULE.SmokeError, "exact sha256"):
|
|
MODULE.platform_image(path, "linux/amd64", "API")
|
|
with self.assertRaisesRegex(MODULE.SmokeError, "exact sha256"):
|
|
MODULE.platform_image(path, "linux/arm64", "API")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|