ativa-ia/tests/test_runtime_port_config.py

25 lines
838 B
Python

import json
import re
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
class RuntimePortConfigTests(unittest.TestCase):
def test_docker_expose_matches_uvicorn_port(self):
dockerfile = (REPO_ROOT / "rag-api/Dockerfile").read_text(encoding="utf-8")
expose = re.search(r"(?m)^EXPOSE\s+(\d+)\s*$", dockerfile)
command = re.search(r"(?m)^CMD\s+(\[.*\])\s*$", dockerfile)
self.assertIsNotNone(expose, "Dockerfile precisa declarar uma porta EXPOSE")
self.assertIsNotNone(command, "Dockerfile precisa declarar o comando do runtime")
command_args = json.loads(command.group(1))
port_index = command_args.index("--port") + 1
self.assertEqual(expose.group(1), command_args[port_index])
if __name__ == "__main__":
unittest.main()