//! Integration tests for docker-manager
//!
//! These tests require a running Docker daemon.
//! Run with: cargo test --test integration_tests

use lmrc_docker::{DockerClient, DockerError, Result};

/// Test that we can create a Docker client
#[tokio::test]
async fn test_client_creation() -> Result<()> {
    let client = DockerClient::new()?;
    assert!(client.inner().version().await.is_ok());
    Ok(())
}

/// Test ping functionality
#[tokio::test]
async fn test_ping() -> Result<()> {
    let client = DockerClient::new()?;
    client.ping().await?;
    Ok(())
}

/// Test container builder configuration
#[tokio::test]
async fn test_container_builder() -> Result<()> {
    let client = DockerClient::new()?;

    // Just test that the builder can be created and configured
    // We don't actually create the container to avoid Docker daemon dependency
    let _builder = client
        .containers()
        .create("alpine:latest")
        .name("test-container")
        .env("TEST", "value")
        .port(8080, 80, "tcp");

    Ok(())
}

/// Test image builder configuration
#[tokio::test]
async fn test_image_builder() -> Result<()> {
    let client = DockerClient::new()?;

    // Just test that the builder can be created and configured
    let _builder = client
        .images()
        .build("test:latest")
        .dockerfile("Dockerfile")
        .build_arg("VERSION", "1.0.0")
        .label("test", "value");

    Ok(())
}

/// Test error conversion
#[test]
fn test_error_conversions() {
    let err: DockerError = "test error".into();
    assert_eq!(err.to_string(), "test error");

    let err: DockerError = String::from("another error").into();
    assert_eq!(err.to_string(), "another error");
}

/// Test error types
#[test]
fn test_error_types() {
    let err = DockerError::ContainerNotFound("test-id".to_string());
    assert!(err.to_string().contains("Container not found"));

    let err = DockerError::ImageNotFound("test:latest".to_string());
    assert!(err.to_string().contains("Image not found"));

    let err = DockerError::BuildFailed("syntax error".to_string());
    assert!(err.to_string().contains("Docker build failed"));
}

/// Test Result type alias
#[test]
fn test_result_type() {
    fn returns_ok() -> Result<String> {
        Ok("success".to_string())
    }

    fn returns_err() -> Result<String> {
        Err(DockerError::Other("failure".to_string()))
    }

    assert!(returns_ok().is_ok());
    assert!(returns_err().is_err());
}
