Files
devx/tests/unit/test_validate_deploy_ref.py
T
emil ef3b882e5b
Post-merge / detect-type (push) Successful in 13s
Post-merge / validate-commit-msg (push) Successful in 10s
Post-merge / configure-repo (push) Successful in 28s
Post-merge / vikunja (push) Successful in 44s
Post-merge / sync-wiki (push) Successful in 58s
Post-merge / release (push) Successful in 1m7s
Post-merge / publish (push) Successful in 44s
Post-merge / badges (push) Successful in 1m6s
DEVX-124: feat: extract shared utilities from infra and grm into devx
2026-07-09 11:51:50 +00:00

71 lines
3.0 KiB
Python

"""Unit tests for devx.ci.validate_deploy_ref."""
from __future__ import annotations
from pathlib import Path
from unittest.mock import MagicMock, patch
from click.testing import CliRunner
from devx.ci.validate_deploy_ref import main
class TestValidateDeployRef:
def test_valid_tag_prints_ref(self, tmp_path: Path) -> None:
runner = CliRunner()
with patch("devx.ci.validate_deploy_ref.subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="abcdef1234567890\n", stderr="")
result = runner.invoke(main, ["--tag", "v1.0.0"])
assert result.exit_code == 0
assert "v1.0.0" in result.output
def test_invalid_tag_exits_nonzero(self) -> None:
runner = CliRunner()
with patch("devx.ci.validate_deploy_ref.subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=1, stdout="", stderr="error")
result = runner.invoke(main, ["--tag", "nonexistent"])
assert result.exit_code == 1
assert "does not exist" in result.output
def test_no_tag_without_allow_empty_exits_nonzero(self) -> None:
runner = CliRunner()
result = runner.invoke(main, [])
assert result.exit_code == 1
assert "No tag specified" in result.output
def test_allow_empty_prints_pr_mode(self) -> None:
runner = CliRunner()
result = runner.invoke(main, ["--allow-empty"])
assert result.exit_code == 0
assert "PR mode" in result.output
def test_github_output_writes_ref(self, tmp_path: Path) -> None:
runner = CliRunner()
gh_output = tmp_path / "github_output"
gh_output.write_text("")
with patch("devx.ci.validate_deploy_ref.subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="abcdef12\n", stderr="")
with runner.isolation(env={"GITHUB_OUTPUT": str(gh_output)}):
result = runner.invoke(main, ["--tag", "v1.0.0", "--github-output"])
assert result.exit_code == 0
content = gh_output.read_text()
assert "deploy-ref=v1.0.0" in content
def test_github_output_without_env_var_exits_nonzero(self) -> None:
runner = CliRunner()
with patch("devx.ci.validate_deploy_ref.subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="abcdef12\n", stderr="")
with runner.isolation(env={"GITHUB_OUTPUT": ""}):
result = runner.invoke(main, ["--tag", "v1.0.0", "--github-output"])
assert result.exit_code == 1
assert "GITHUB_OUTPUT" in result.output
def test_allow_empty_with_github_output(self, tmp_path: Path) -> None:
runner = CliRunner()
gh_output = tmp_path / "github_output"
gh_output.write_text("")
with runner.isolation(env={"GITHUB_OUTPUT": str(gh_output)}):
result = runner.invoke(main, ["--allow-empty", "--github-output"])
assert result.exit_code == 0
assert "deploy-ref=" in gh_output.read_text()