Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02669-87ee-7a31-b111-edc95a16e0fa
33 lines
1.7 KiB
Python
33 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SPEC = importlib.util.spec_from_file_location("forge_resources", ROOT / "tools" / "observe_forge_resources.py")
|
|
assert SPEC and SPEC.loader
|
|
module = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(module)
|
|
|
|
|
|
class ForgeResourceTests(unittest.TestCase):
|
|
def test_resource_aggregation_and_residual(self) -> None:
|
|
deployment = {"metadata": {"name": "forgejo-gitea"}, "spec": {"replicas": 1, "template": {"spec": {"containers": [{"resources": {"requests": {"cpu": "100m", "memory": "128Mi"}, "limits": {"cpu": "1", "memory": "1Gi"}}}]}}}, "status": {"availableReplicas": 1}}
|
|
snapshot = {
|
|
"deployments": {"items": [deployment]},
|
|
"pvcs": {"items": [{"metadata": {"name": "data"}, "spec": {"storageClassName": "local-path", "resources": {"requests": {"storage": "10Gi"}}}, "status": {"phase": "Bound"}}]},
|
|
"database": {"spec": {"instances": 1, "storage": {"size": "10Gi"}}, "status": {"readyInstances": 1, "phase": "ready", "conditions": []}},
|
|
"backups": {"items": []},
|
|
"top": None,
|
|
"forge_data_kib": 1024,
|
|
"runner_data_kib": None,
|
|
}
|
|
result = module.build_observation(snapshot, "2026-08-22T00:00:00Z")
|
|
self.assertEqual(100, result["capacity"]["deployments"][0]["requests"]["cpu_millicores"])
|
|
self.assertEqual(1024**2, result["allocation"]["residual"]["forge_data_used_bytes"])
|
|
self.assertIn("forgejo-db has no Backup or ScheduledBackup evidence", result["measurement_gaps"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|