fix(images): keur onbekende platforms niet goed en ververs oude cache
Some checks failed
Deploy server-up (dev) / deploy (push) Has been cancelled
Some checks failed
Deploy server-up (dev) / deploy (push) Has been cancelled
This commit is contained in:
parent
2fa1f83c4e
commit
7507b7f9d8
3 changed files with 35 additions and 3 deletions
|
|
@ -156,7 +156,7 @@ def test_catalogus_vult_de_mongo_versie_in(ci):
|
||||||
(["linux/amd64", "linux/arm64"], ""),
|
(["linux/amd64", "linux/arm64"], ""),
|
||||||
([], "ingetrokken"),
|
([], "ingetrokken"),
|
||||||
(["linux/arm64"], "geen linux/amd64"),
|
(["linux/arm64"], "geen linux/amd64"),
|
||||||
(["?"], ""),
|
(["?"], "platform niet vast te stellen"),
|
||||||
])
|
])
|
||||||
def test_wat_een_image_onbruikbaar_maakt(ci, monkeypatch, platformen, reden):
|
def test_wat_een_image_onbruikbaar_maakt(ci, monkeypatch, platformen, reden):
|
||||||
monkeypatch.setattr(ci.image_controle, "platformen", lambda i: platformen)
|
monkeypatch.setattr(ci.image_controle, "platformen", lambda i: platformen)
|
||||||
|
|
|
||||||
28
tests/test_image_controle_review.py
Normal file
28
tests/test_image_controle_review.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
"""Een onbekend platform is geen bewijs dat een image installeerbaar is."""
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from test_image_cache import ci
|
||||||
|
|
||||||
|
|
||||||
|
def test_onbekend_platform_krijgt_geen_goedkeuring(ci, monkeypatch):
|
||||||
|
monkeypatch.setattr(ci.image_controle, "platformen", lambda image: ["?"])
|
||||||
|
reden, _ = ci.controleer("voorbeeld/app:1")
|
||||||
|
assert reden, "Zonder platformbewijs mag de controle niet slagen"
|
||||||
|
|
||||||
|
|
||||||
|
def test_onbekend_platform_wordt_niet_als_succes_gecached(ci, monkeypatch, tmp_path):
|
||||||
|
monkeypatch.setattr(sys, "argv", ["controleer_images.py", "--json"])
|
||||||
|
monkeypatch.setattr(ci, "images", lambda: {"voorbeeld/app:1": ["proefapp"]})
|
||||||
|
monkeypatch.setattr(ci, "belooft_arm64", lambda: {"proefapp"})
|
||||||
|
monkeypatch.setattr(ci.image_controle, "platformen", lambda image: ["?"])
|
||||||
|
assert ci.main() == 1, "De wekelijkse CI mag een onbekend platform niet goedkeuren"
|
||||||
|
cache = json.loads((tmp_path / "images.json").read_text())
|
||||||
|
assert "voorbeeld/app:1" not in cache
|
||||||
|
|
||||||
|
|
||||||
|
def test_oude_cache_met_onbekende_platformen_wordt_opnieuw_gecontroleerd(ci):
|
||||||
|
nu = time.time()
|
||||||
|
cache = {"voorbeeld/app:1": {"ts": nu, "platformen": ["?"]}}
|
||||||
|
assert ci.te_controleren({"voorbeeld/app:1": ["proefapp"]}, cache, nu) == ["voorbeeld/app:1"]
|
||||||
|
|
@ -159,7 +159,9 @@ def te_controleren(alles, cache: dict, nu: float) -> list[str]:
|
||||||
def vers(i):
|
def vers(i):
|
||||||
c = cache.get(i)
|
c = cache.get(i)
|
||||||
return (isinstance(c, dict) and isinstance(c.get("ts"), (int, float))
|
return (isinstance(c, dict) and isinstance(c.get("ts"), (int, float))
|
||||||
and isinstance(c.get("platformen"), list) and houdbaar_tot(i, c["ts"]) >= nu)
|
and isinstance(c.get("platformen"), list)
|
||||||
|
and "linux/amd64" in c["platformen"]
|
||||||
|
and houdbaar_tot(i, c["ts"]) >= nu)
|
||||||
return [i for i in alles if not vers(i)]
|
return [i for i in alles if not vers(i)]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -179,7 +181,9 @@ def controleer(image: str) -> tuple[str, list[str]]:
|
||||||
else:
|
else:
|
||||||
if not platformen:
|
if not platformen:
|
||||||
return "ingetrokken (geen platform om te draaien)", []
|
return "ingetrokken (geen platform om te draaien)", []
|
||||||
if "?" not in platformen and "linux/amd64" not in platformen:
|
if platformen == ["?"]:
|
||||||
|
return "platform niet vast te stellen", platformen
|
||||||
|
if "linux/amd64" not in platformen:
|
||||||
return "geen linux/amd64", platformen
|
return "geen linux/amd64", platformen
|
||||||
return "", platformen
|
return "", platformen
|
||||||
if poging < POGINGEN - 1:
|
if poging < POGINGEN - 1:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue