#!/usr/bin/env python3
"""
Auto-generated CLI tests for server commands

Generated by: tests/generators/test_generator.py
DO NOT EDIT MANUALLY - Regenerate with: python tests/generators/test_generator.py

This file provides comprehensive coverage of server CLI commands, options,
and parameter combinations. Tests are automatically generated by introspecting
the Click command structure.
"""

import subprocess
import os

# Set testing environment variable
os.environ["N8N_DEPLOY_TESTING"] = "1"

CLI_COMMAND = ["./n8n-deploy"]


def test_server_create_help():
    """Test server  create --help"""
    result = subprocess.run(CLI_COMMAND + ["server", "create", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server create --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_create_data_dir_valid_path():
    """Test server  create with valid --data-dir"""
    result = subprocess.run(
        CLI_COMMAND + ["server", "create", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server create --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_create_with_positional_args():
    """Test server  create with positional arguments"""
    result = subprocess.run(
        CLI_COMMAND + ["server", "create", "test_name", "test_url"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server create test_name test_url\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_create_missing_required_args():
    """Test server  create with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "create"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server create\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_keys_help():
    """Test server  keys --help"""
    result = subprocess.run(CLI_COMMAND + ["server", "keys", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server keys --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_keys_output_json_flag():
    """Test server  keys with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "keys", "--output-json"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server keys --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_keys_output_table_flag():
    """Test server  keys with --output-table flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "keys", "--output-table"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server keys --output-table\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_keys_with_positional_args():
    """Test server  keys with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "keys", "test_server_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server keys test_server_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_keys_missing_required_args():
    """Test server  keys with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "keys"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server keys\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_list_help():
    """Test server  list --help"""
    result = subprocess.run(CLI_COMMAND + ["server", "list", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server list --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_list_no_args():
    """Test server  list with no arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "list"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server list\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_list_active_flag():
    """Test server  list with --active flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "list", "--active"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server list --active\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_list_output_json_flag():
    """Test server  list with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "list", "--output-json"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server list --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_list_output_table_flag():
    """Test server  list with --output-table flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "list", "--output-table"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server list --output-table\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_help():
    """Test server  remove --help"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_confirm_flag():
    """Test server  remove with --confirm flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove", "--confirm"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove --confirm\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_key_action_flag():
    """Test server  remove with --key-action flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove", "--key-action"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove --key-action\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_key_action_flag():
    """Test server  remove with --key-action flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove", "--key-action"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove --key-action\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_with_positional_args():
    """Test server  remove with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove", "test_server_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove test_server_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_remove_missing_required_args():
    """Test server  remove with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "remove"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server remove\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_help():
    """Test server  ssl --help"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_skip_verify_flag():
    """Test server  ssl with --skip-verify flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl", "--skip-verify"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl --skip-verify\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_verify_flag():
    """Test server  ssl with --verify flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl", "--verify"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl --verify\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_output_json_flag():
    """Test server  ssl with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl", "--output-json"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_with_positional_args():
    """Test server  ssl with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl", "test_server_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl test_server_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_server_ssl_missing_required_args():
    """Test server  ssl with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["server", "ssl"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: server ssl\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )
