from pathlib import Path import unittest WORKFLOW = Path(__file__).resolve().parents[1] / ".gitea/workflows/deploy.yml" CONFIG_TEMPLATE = Path(__file__).resolve().parents[1] / "server/manifest/config/config.template" class DeployWorkflowContractTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.workflow = WORKFLOW.read_text(encoding="utf-8") def test_targets_pro_branch_and_single_runner(self): self.assertIn("push:", self.workflow) self.assertIn("- pro", self.workflow) self.assertIn("workflow_dispatch:", self.workflow) self.assertIn("runs-on: deploy-host", self.workflow) self.assertIn("concurrency:", self.workflow) def test_builds_and_pushes_pro_image(self): self.assertIn("git.olns.shop/pro/im_manager", self.workflow) self.assertIn("docker push", self.workflow) self.assertIn(":pro", self.workflow) def test_deploys_compose_service_with_pinned_host_key(self): self.assertIn("DEPLOY_SSH_KEY", self.workflow) self.assertIn("DEPLOY_KNOWN_HOSTS", self.workflow) self.assertIn("StrictHostKeyChecking=yes", self.workflow) self.assertIn("docker compose pull im-manager", self.workflow) self.assertIn("docker compose up -d --no-deps --wait im-manager", self.workflow) def test_removes_old_kubernetes_and_registry_targets(self): self.assertNotIn("kubectl", self.workflow) self.assertNotIn("KUBECONFIG", self.workflow) self.assertNotIn("git.118im.com", self.workflow) class ProductionConfigContractTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.config = CONFIG_TEMPLATE.read_text(encoding="utf-8") def test_disables_debug_surfaces_and_verbose_request_logging(self): self.assertIn(" debug: false", self.config) self.assertNotIn("debug: true", self.config) self.assertIn(' mode: "product"', self.config) self.assertIn(' level: "info"', self.config) self.assertIn(" accessLogEnabled: false", self.config) self.assertIn(" pprofEnabled: false", self.config) self.assertIn(" stdout: false", self.config) if __name__ == "__main__": unittest.main()