|
| 1 | +import json |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +from typer.testing import CliRunner |
| 5 | + |
| 6 | +from fastapi_cloud_cli.cli import cloud_app as app |
| 7 | +from fastapi_cloud_cli.commands.setup_ci import _get_workflow_content |
| 8 | + |
| 9 | +runner = CliRunner() |
| 10 | + |
| 11 | + |
| 12 | +def test_print_workflow_uses_default_branch() -> None: |
| 13 | + with patch( |
| 14 | + "fastapi_cloud_cli.commands.ci.print_workflow._get_default_branch", |
| 15 | + return_value="develop", |
| 16 | + ): |
| 17 | + result = runner.invoke(app, ["ci", "print-workflow"]) |
| 18 | + |
| 19 | + assert result.exit_code == 0 |
| 20 | + assert result.stdout == _get_workflow_content("develop") |
| 21 | + assert result.stderr == "" |
| 22 | + |
| 23 | + |
| 24 | +def test_print_workflow_uses_branch_option() -> None: |
| 25 | + result = runner.invoke(app, ["ci", "print-workflow", "--branch", "main"]) |
| 26 | + |
| 27 | + assert result.exit_code == 0 |
| 28 | + assert result.stdout == _get_workflow_content("main") |
| 29 | + assert result.stderr == "" |
| 30 | + |
| 31 | + |
| 32 | +def test_print_workflow_json_outputs_envelope() -> None: |
| 33 | + result = runner.invoke(app, ["ci", "print-workflow", "--branch", "main", "--json"]) |
| 34 | + |
| 35 | + assert result.exit_code == 0 |
| 36 | + assert json.loads(result.stdout) == { |
| 37 | + "data": { |
| 38 | + "filename": "deploy.yml", |
| 39 | + "content": _get_workflow_content("main"), |
| 40 | + } |
| 41 | + } |
| 42 | + assert result.stderr == "" |
0 commit comments