|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import subprocess |
| 4 | +import sysconfig |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | + |
| 9 | +COMMANDS = ("api", "logs", "bump-versions", "run-migrations") |
| 10 | +GUIDE_URL = "https://docs.braintrust.dev/admin/self-hosting/aws-cloudformation" |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def cli(): |
| 15 | + executable = shutil.which("braintrust", path=sysconfig.get_path("scripts")) |
| 16 | + assert executable is not None |
| 17 | + return executable |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.parametrize("command", [(), *((name,) for name in COMMANDS)]) |
| 21 | +def test_install_help(cli, command): |
| 22 | + result = subprocess.run( |
| 23 | + [cli, "install", *command, "--help"], |
| 24 | + capture_output=True, |
| 25 | + text=True, |
| 26 | + check=False, |
| 27 | + ) |
| 28 | + |
| 29 | + assert result.returncode == 0, result.stderr |
| 30 | + assert result.stderr == "" |
| 31 | + assert "deprecated" in result.stdout |
| 32 | + assert "Terraform" not in result.stdout |
| 33 | + assert GUIDE_URL in result.stdout |
| 34 | + if not command: |
| 35 | + assert result.stdout.count("(deprecated)") == len(COMMANDS) |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.parametrize("command", COMMANDS) |
| 39 | +def test_install_warns_on_stderr_before_aws_setup(cli, command, tmp_path): |
| 40 | + result = subprocess.run( |
| 41 | + [cli, "install", command, "test-stack"], |
| 42 | + capture_output=True, |
| 43 | + text=True, |
| 44 | + check=False, |
| 45 | + env={ |
| 46 | + **os.environ, |
| 47 | + "AWS_CONFIG_FILE": str(tmp_path / "config"), |
| 48 | + "AWS_SHARED_CREDENTIALS_FILE": str(tmp_path / "credentials"), |
| 49 | + "AWS_DEFAULT_PROFILE": "missing-test-profile", |
| 50 | + "AWS_PROFILE": "missing-test-profile", |
| 51 | + "AWS_EC2_METADATA_DISABLED": "true", |
| 52 | + }, |
| 53 | + ) |
| 54 | + |
| 55 | + assert result.returncode == 1 |
| 56 | + warning = result.stderr.splitlines()[0] |
| 57 | + assert warning.startswith("Warning:") |
| 58 | + assert "deprecated" in warning |
| 59 | + assert "Terraform" not in warning |
| 60 | + assert GUIDE_URL in warning |
| 61 | + assert GUIDE_URL not in result.stdout |
| 62 | + |
| 63 | + |
| 64 | +def test_install_requires_subcommand(cli): |
| 65 | + result = subprocess.run( |
| 66 | + [cli, "install"], |
| 67 | + capture_output=True, |
| 68 | + text=True, |
| 69 | + check=False, |
| 70 | + ) |
| 71 | + |
| 72 | + assert result.returncode == 2 |
| 73 | + assert "usage:" in result.stderr |
| 74 | + assert "Warning:" not in result.stderr |
0 commit comments