import re
import unittest
from pathlib import Path


class DeployWorkflowTests(unittest.TestCase):
    def test_deploy_workflow_triggers_on_master_pushes(self):
        workflow_path = Path(__file__).resolve().parents[1] / ".gitea" / "workflows" / "deploy-ftp.yml"
        workflow_text = workflow_path.read_text(encoding="utf-8")

        branch_block_match = re.search(
            r"on:\s*\n\s*push:\s*\n\s*branches:\s*\n(?P<branches>(?:\s*-\s*[^\n]+\n)+)",
            workflow_text,
        )

        self.assertIsNotNone(branch_block_match, "workflow should define push branches")
        branches = re.findall(r"-\s*([^\n]+)", branch_block_match.group("branches"))

        self.assertEqual(branches, ["master"])


if __name__ == "__main__":
    unittest.main()
