//! Integration tests for k3s-manager
//!
//! These tests are designed to run against actual infrastructure and are typically
//! ignored by default. They can be run with:
//!
//! ```bash
//! cargo test --test integration_tests -- --ignored --test-threads=1
//! ```

use lmrc_k3s::K3sManager;

#[test]
fn test_manager_creation() {
    let manager = K3sManager::builder().token("test-token").build();

    // Manager created successfully
    assert!(manager.get_cluster_state().is_none());
}

#[test]
fn test_manager_with_custom_version() {
    let _manager = K3sManager::builder()
        .version("v1.27.0+k3s1")
        .token("test-token")
        .disable(vec!["traefik".to_string()])
        .build();

    // Manager created successfully with custom configuration
}

/// This test requires actual infrastructure and should only be run manually
/// with valid IP addresses and SSH access configured.
///
/// Run with:
/// ```bash
/// MASTER_IP=192.168.1.10 cargo test --test integration_tests test_cluster_setup -- --ignored --nocapture
/// ```
#[tokio::test]
#[ignore]
async fn test_cluster_setup() {
    let master_ip = std::env::var("MASTER_IP")
        .expect("MASTER_IP environment variable must be set for this test");

    let manager = K3sManager::builder().token("test-cluster-token").build();

    // Test installation check
    let result = manager.is_installed(&master_ip).await;
    assert!(result.is_ok());
}

/// Test that verifies the builder pattern works correctly
#[test]
fn test_builder_pattern() {
    let _manager = K3sManager::builder()
        .version("v1.28.5+k3s1")
        .token("secure-token")
        .disable(vec!["traefik".to_string(), "servicelb".to_string()])
        .ssh_username("admin")
        .ssh_key_path("/custom/path/id_rsa")
        .build();

    // Builder pattern works correctly
}

#[test]
#[should_panic(expected = "Token must be set")]
fn test_builder_requires_token() {
    K3sManager::builder().build();
}

#[test]
fn test_builder_defaults() {
    let manager = K3sManager::builder().token("token").build();

    // Manager created with defaults
    assert!(manager.get_cluster_state().is_none());
}

#[test]
fn test_builder_with_ssh_password() {
    let _manager = K3sManager::builder()
        .token("token")
        .ssh_password("secret")
        .build();

    // Manager created with password authentication
}
