|
15 | 15 | THE_VALUE = "test_secret_value_not_real_for_testing_only" |
16 | 16 |
|
17 | 17 |
|
18 | | -@pytest.mark.e2e |
19 | | -@pytest.mark.scheduled |
20 | | -@pytest.mark.timeout(timeout=60) |
21 | | -def test_cli_health_json(runner: CliRunner, record_property) -> None: |
22 | | - """Check health is true.""" |
| 18 | +@pytest.mark.unit |
| 19 | +@patch("aignostics.system._cli._service") |
| 20 | +def test_cli_health_json_format(mock_service: MagicMock, runner: CliRunner, record_property) -> None: |
| 21 | + """Check health CLI renders UP status correctly as JSON.""" |
23 | 22 | record_property("tested-item-id", "TEST-SYSTEM-CLI-HEALTH-JSON") |
| 23 | + from aignostics.utils import Health |
| 24 | + |
| 25 | + mock_service.health.return_value = Health(status=Health.Code.UP) |
24 | 26 | result = runner.invoke(cli, ["system", "health"]) |
| 27 | + assert result.exit_code == 0 |
25 | 28 | assert normalize_output(result.stdout).startswith('{ "status": "UP"') |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.unit |
| 32 | +@patch("aignostics.system._cli._service") |
| 33 | +def test_cli_health_yaml_format(mock_service: MagicMock, runner: CliRunner, record_property) -> None: |
| 34 | + """Check health CLI renders UP status correctly as YAML.""" |
| 35 | + record_property("tested-item-id", "TEST-SYSTEM-CLI-HEALTH-YAML") |
| 36 | + from aignostics.utils import Health |
| 37 | + |
| 38 | + mock_service.health.return_value = Health(status=Health.Code.UP) |
| 39 | + result = runner.invoke(cli, ["system", "health", "--output-format", "yaml"]) |
26 | 40 | assert result.exit_code == 0 |
| 41 | + assert "status: UP" in result.stdout |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.e2e |
| 45 | +@pytest.mark.scheduled |
| 46 | +@pytest.mark.timeout(timeout=60) |
| 47 | +def test_cli_health_json(runner: CliRunner) -> None: |
| 48 | + """Check health CLI returns valid JSON with a valid status value.""" |
| 49 | + import json |
| 50 | + |
| 51 | + result = runner.invoke(cli, ["system", "health"]) |
| 52 | + data = json.loads(result.stdout) |
| 53 | + assert data["status"] in {"UP", "DEGRADED", "DOWN"} |
27 | 54 |
|
28 | 55 |
|
29 | 56 | @pytest.mark.e2e |
30 | 57 | @pytest.mark.timeout(timeout=30) |
31 | | -def test_cli_health_yaml(runner: CliRunner, record_property) -> None: |
32 | | - """Check health is true.""" |
33 | | - record_property("tested-item-id", "TEST-SYSTEM-CLI-HEALTH-YAML") |
| 58 | +def test_cli_health_yaml(runner: CliRunner) -> None: |
| 59 | + """Check health CLI returns valid YAML with a valid status value.""" |
| 60 | + import yaml |
| 61 | + |
34 | 62 | result = runner.invoke(cli, ["system", "health", "--output-format", "yaml"]) |
35 | | - assert "status: UP" in result.stdout |
36 | | - assert result.exit_code == 0 |
| 63 | + data = yaml.safe_load(result.stdout) |
| 64 | + assert data["status"] in {"UP", "DEGRADED", "DOWN"} |
37 | 65 |
|
38 | 66 |
|
39 | 67 | @pytest.mark.e2e |
|
0 commit comments