//! Extension Loading Tests

use provisioning_orchestrator::extensions::{ExtensionManager, ExtensionMetadata, ExtensionType};

#[tokio::test]
async fn test_extension_manager_initialization() {
    let manager = ExtensionManager::new(
        "/usr/local/bin/nu".to_string(),
        "/usr/local/bin/provisioning".to_string(),
    );

    let loaded = manager.list_loaded_extensions().await;
    assert_eq!(loaded.len(), 0);
}

#[tokio::test]
async fn test_extension_type_display() {
    assert_eq!(ExtensionType::Provider.to_string(), "provider");
    assert_eq!(ExtensionType::Taskserv.to_string(), "taskserv");
    assert_eq!(ExtensionType::Cluster.to_string(), "cluster");
}

#[tokio::test]
async fn test_extension_cache_clear() {
    let manager = ExtensionManager::new(
        "/usr/local/bin/nu".to_string(),
        "/usr/local/bin/provisioning".to_string(),
    );

    // Clear empty cache should succeed
    manager.clear_cache().await;

    let loaded = manager.list_loaded_extensions().await;
    assert_eq!(loaded.len(), 0);
}

#[tokio::test]
async fn test_extension_metadata_creation() {
    let metadata = ExtensionMetadata {
        name: "kubernetes".to_string(),
        version: "1.28.0".to_string(),
        description: "Kubernetes container orchestrator".to_string(),
        extension_type: ExtensionType::Taskserv,
        dependencies: vec!["containerd".to_string(), "etcd".to_string()],
        author: Some("provisioning-team".to_string()),
        repository: None,
    };

    assert_eq!(metadata.name, "kubernetes");
    assert_eq!(metadata.version, "1.28.0");
    assert_eq!(metadata.extension_type, ExtensionType::Taskserv);
    assert_eq!(metadata.dependencies.len(), 2);
}

#[tokio::test]
async fn test_is_extension_loaded() {
    let manager = ExtensionManager::new(
        "/usr/local/bin/nu".to_string(),
        "/usr/local/bin/provisioning".to_string(),
    );

    // Nothing loaded initially
    let is_loaded = manager
        .is_extension_loaded(ExtensionType::Taskserv, "kubernetes")
        .await;
    assert!(!is_loaded);
}

#[test]
fn test_extension_type_equality() {
    assert_eq!(ExtensionType::Provider, ExtensionType::Provider);
    assert_ne!(ExtensionType::Provider, ExtensionType::Taskserv);
    assert_ne!(ExtensionType::Taskserv, ExtensionType::Cluster);
}
