mirror of
https://github.com/azaion/loader.git
synced 2026-04-22 10:46:32 +00:00
Add E2E tests, fix bugs
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
COMPOSE_FILE = os.path.join(os.path.dirname(__file__), "..", "docker-compose.test.yml")
|
||||
|
||||
|
||||
def _compose_exec(cmd: str):
|
||||
subprocess.run(
|
||||
["docker", "compose", "-f", COMPOSE_FILE, "exec", "system-under-test",
|
||||
"bash", "-c", cmd],
|
||||
capture_output=True, timeout=15,
|
||||
)
|
||||
|
||||
|
||||
def _wait_for_settled(base_url, client, timeout=30):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
resp = client.get(f"{base_url}/unlock/status")
|
||||
state = resp.json()["state"]
|
||||
if state in ("idle", "error", "ready"):
|
||||
return state
|
||||
time.sleep(0.5)
|
||||
return None
|
||||
|
||||
|
||||
def test_unlock_status_idle(base_url, api_client):
|
||||
# Act
|
||||
response = api_client.get(f"{base_url}/unlock/status")
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["state"] == "idle"
|
||||
assert data["error"] is None
|
||||
|
||||
|
||||
def test_unlock_missing_archive(base_url, api_client):
|
||||
# Arrange
|
||||
payload = {"email": "test@azaion.com", "password": "testpass"}
|
||||
|
||||
# Act
|
||||
response = api_client.post(f"{base_url}/unlock", json=payload)
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_unlock_concurrent_returns_current_state(base_url, api_client):
|
||||
# Arrange
|
||||
_compose_exec("dd if=/dev/urandom of=/tmp/test.enc bs=1024 count=1 2>/dev/null")
|
||||
payload = {"email": "test@azaion.com", "password": "testpass"}
|
||||
|
||||
try:
|
||||
# Act
|
||||
first = api_client.post(f"{base_url}/unlock", json=payload)
|
||||
second = api_client.post(f"{base_url}/unlock", json=payload)
|
||||
|
||||
# Assert
|
||||
assert first.status_code == 200
|
||||
assert second.status_code == 200
|
||||
assert second.json()["state"] != "idle"
|
||||
finally:
|
||||
_compose_exec("rm -f /tmp/test.enc /tmp/test.tar")
|
||||
_wait_for_settled(base_url, api_client)
|
||||
Reference in New Issue
Block a user