//! Integration test: requires Docker daemon running.
//! Run with: cargo test -p aws-local-rds --test postgres_integration -- --ignored

use aws_local_rds::docker::DockerManager;

#[tokio::test]
#[ignore]
async fn create_and_drop_database() {
    let docker = DockerManager::new().expect("Docker not available");

    let port = docker
        .ensure_postgres(Some("16"))
        .await
        .expect("failed to start Postgres");

    docker
        .create_database(port, "test_integration_db", "testuser", "testpass")
        .await
        .expect("failed to create database");

    // Verify we can connect to the new database
    let conn_str = format!(
        "host=127.0.0.1 port={port} user=testuser password=testpass dbname=test_integration_db"
    );
    let (client, connection) = tokio_postgres::connect(&conn_str, tokio_postgres::NoTls)
        .await
        .expect("failed to connect to new database");

    tokio::spawn(async move { connection.await.ok(); });

    let row = client
        .query_one("SELECT 1 as n", &[])
        .await
        .expect("query failed");
    let n: i32 = row.get("n");
    assert_eq!(n, 1);

    // Clean up
    docker
        .drop_database(port, "test_integration_db", "testuser")
        .await
        .expect("failed to drop database");
}
