#!/usr/bin/env python3
"""
Auto-generated CLI tests for db 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 db 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_db_backup_help():
    """Test db  backup --help"""
    result = subprocess.run(CLI_COMMAND + ["db", "backup", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db backup --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_db_backup_data_dir_valid_path():
    """Test db  backup with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["db", "backup", "--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: db backup --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_backup_with_positional_args():
    """Test db  backup with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["db", "backup", "test_backup_path"], 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: db backup test_backup_path\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_compact_help():
    """Test db  compact --help"""
    result = subprocess.run(CLI_COMMAND + ["db", "compact", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db compact --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_db_compact_no_args():
    """Test db  compact with no arguments"""
    result = subprocess.run(CLI_COMMAND + ["db", "compact"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db compact\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_compact_data_dir_valid_path():
    """Test db  compact with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["db", "compact", "--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: db compact --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_init_help():
    """Test db  init --help"""
    result = subprocess.run(CLI_COMMAND + ["db", "init", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db init --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_db_init_no_args():
    """Test db  init with no arguments"""
    result = subprocess.run(CLI_COMMAND + ["db", "init"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db init\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_init_data_dir_valid_path():
    """Test db  init with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["db", "init", "--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: db init --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_init_auto_import_flag():
    """Test db  init with --auto-import flag"""
    result = subprocess.run(CLI_COMMAND + ["db", "init", "--auto-import"], 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: db init --auto-import\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_init_output_json_flag():
    """Test db  init with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["db", "init", "--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: db init --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_status_help():
    """Test db  status --help"""
    result = subprocess.run(CLI_COMMAND + ["db", "status", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db status --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_db_status_no_args():
    """Test db  status with no arguments"""
    result = subprocess.run(CLI_COMMAND + ["db", "status"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: db status\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_status_data_dir_valid_path():
    """Test db  status with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["db", "status", "--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: db status --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_db_status_output_json_flag():
    """Test db  status with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["db", "status", "--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: db status --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
