"""Test ls command.""" import json import allure import pytest from .types import ClientRegistry, CommandRunner @allure.title("Test 'ls' command") @pytest.mark.asyncio async def test_list_secrets(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None: """Test the list secrets 'ls' command.""" secrets = ["restricted", "mystery", "confidential", "classified"] await client_registry["add_client"]("test-client", secrets) result = await ssh_command_runner("test-client", "ls") assert result.stdout is not None assert isinstance(result.stdout, str) assert result.exit_status == 0 returned_secrets: list[str] = [] for line in result.stdout.splitlines(): if line.strip().startswith("-"): returned_secrets.append(line.strip()[2:]) assert returned_secrets == secrets @allure.title("Test 'ls' command as JSON") @pytest.mark.asyncio async def test_list_secrets(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None: """Run the list secrets 'ls' command with the JSON flag.""" secrets = ["undisclosed", "untold", "top_secret"] await client_registry["add_client"]("test-client", secrets) result = await ssh_command_runner("test-client", "ls --json") assert result.exit_status == 0 assert isinstance(result.stdout, str) secrets_json = json.loads(result.stdout) assert isinstance(secrets_json, dict) returned_secrets = secrets_json.get("secrets") assert returned_secrets is not None assert returned_secrets == secrets short_result = await ssh_command_runner("test-client", "ls -j") assert short_result.stdout == result.stdout @allure.title("Test the 'ls' command help") @pytest.mark.enable_registration(True) @pytest.mark.asyncio async def test_register_cmd_help(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None: """Test running ls --help""" await client_registry["add_client"]("test-client", ["mysecret"]) result = await ssh_command_runner("test-client", "ls --help") assert result.exit_status == 0 print(result.stdout) assert isinstance(result.stdout, str) lines = result.stdout.splitlines() assert lines[0] == "ls [-j --json]" assert len(lines) > 4