test: pin the sweep outcome per tool in a baseline, seed a GPG key, fail loudly when seeding finds no run
This commit is contained in:
1 parent
84b361962e
commit
9e51f72ec9
6 files changed
+761
-14
No files matched your search
@@ -16,6 +16,7 @@ from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
||||
|
||||
from tests.integration.harness import GiteaInstance, HarnessError
|
||||
from tests.integration.static_keys import GPG_EMAILS, GPG_PUBLIC_KEYS
|
||||
|
||||
Ctx = dict[str, Any]
|
||||
|
||||
@@ -370,7 +371,11 @@ def seed(gitea: GiteaInstance, user: str, user_token: str) -> Ctx:
|
||||
|
||||
# Current user: email, follow, star, watch, block.
|
||||
c["email"] = f"sweep-{sfx}@example.test"
|
||||
s.call("POST", "/user/emails", json={"emails": [c["email"]]})
|
||||
s.call("POST", "/user/emails", json={"emails": [c["email"], *GPG_EMAILS]})
|
||||
# Gitea only accepts a GPG key whose identity matches an email of the account.
|
||||
c["gpg_key"] = s.call(
|
||||
"POST", "/user/gpg_keys", json={"armored_public_key": GPG_PUBLIC_KEYS[0]}
|
||||
)["id"]
|
||||
s.call("PUT", f"/user/following/{user}")
|
||||
s.call("PUT", f"/user/starred/{admin}/{repo}")
|
||||
s.call("PUT", f"{base}/subscription")
|
||||
@@ -419,8 +424,12 @@ def _project(s: Seeder, c: Ctx, scope: str, path: str) -> None:
|
||||
|
||||
|
||||
def _find_run(s: Seeder, base: str) -> tuple[Any, Any]:
|
||||
"""Return ``(run id, job id)`` of the first workflow run, or ``(1, 1)`` if none appeared."""
|
||||
deadline = time.monotonic() + 10
|
||||
"""Return ``(run id, job id)`` of the first workflow run; fail when none appears.
|
||||
|
||||
A made-up id would only turn every dependent tool into a 404, which the sweep would
|
||||
accept as documented, so a missing run is a seeding failure.
|
||||
"""
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline:
|
||||
runs = s.call("GET", f"{base}/actions/runs")
|
||||
entries = runs.get("workflow_runs") or []
|
||||
@@ -431,15 +440,15 @@ def _find_run(s: Seeder, base: str) -> tuple[Any, Any]:
|
||||
if job_entries:
|
||||
return run_id, job_entries[0]["id"]
|
||||
time.sleep(0.5)
|
||||
return 1, 1
|
||||
raise HarnessError("seed: the push of the workflow file did not create a workflow run")
|
||||
|
||||
|
||||
def _find_notification(s: Seeder, admin: str) -> Any:
|
||||
"""Return the id of a notification of the admin if one exists, else 1."""
|
||||
deadline = time.monotonic() + 5
|
||||
"""Return the id of a notification of the admin; fail when none appears."""
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline:
|
||||
listing = s.call("GET", "/notifications", params={"all": "true"})
|
||||
if listing:
|
||||
return listing[0]["id"]
|
||||
time.sleep(0.5)
|
||||
return 1
|
||||
raise HarnessError(f"seed: no notification arrived for {admin}")
|
||||
Reference in new issue
Block a user