Repository: launchbadge/sqlx
File: tests/postgres/postgres.rs (Rust)

Code before:
)"#,
    )
    .execute(&mut conn)
    .await?;

    let rows_affected =
        sqlx::query("insert into person(id, name, birthdate) select * from unnest($1, $2, $3)")
            // owned value
            .bind(people.iter().map(|p| p.id).bind_iter())
            // borrowed value
            .bind(people.iter().map(|p| &p.name).bind_iter())
            .bind(people.iter().map(|p| &p.birthdate).bind_iter())
            .execute(&mut conn)
            .await?
            .rows_affected();
    assert_eq!(rows_affected, 2);

    let p_query = sqlx::query_as::<_, Person>("select * from person order by id")
        .fetch_all(&mut conn)
        .await?;

    assert_eq!(people, p_query);
    Ok(())
}

#[allow(unused)]
async fn test_pg_copy_chunked() -> anyhow::Result<()> {
    let mut conn = new::<Postgres>().await?;

    let mut row = "1".repeat(PG_COPY_MAX_DATA_LEN / 10 - 1);
    row.push_str("\n");

    // creates a payload with COPY_MAX_DATA_LEN + 1 as size
    let mut payload = row.repeat(10);
    payload.push_str("12345678\n");

    assert_eq!(payload.len(), PG_COPY_MAX_DATA_LEN + 1);

    let mut copy = conn.copy_in_raw("COPY products(name) FROM STDIN").await?;

    assert!(copy.send(payload.as_bytes()).await.is_ok());
    assert!(copy.finish().await.is_ok());
    Ok(())
}

async fn test_copy_in_error_case(query: &str, expected_error: &str) -> anyhow::Result<()> {
    let mut conn = new::<Postgres>().await?;
    conn.execute("CREATE TEMPORARY TABLE IF NOT EXISTS invalid_copy_target (id int4)")
        .await?;
    // Try the COPY operation
    match conn.copy_in_raw(query).await {

Review comment (bug):
I'm not sure why this isn't marked as a test at all. Did you try running it?

If it's broken let's just mark it:
```suggestion
#[sqlx_macros::test]
#[ignore]
```

Code after:
)"#,
    )
    .execute(&mut conn)
    .await?;

    let rows_affected =
        sqlx::query("insert into person(id, name, birthdate) select * from unnest($1, $2, $3)")
            // owned value
            .bind(people.iter().map(|p| p.id).bind_iter())
            // borrowed value
            .bind(people.iter().map(|p| &p.name).bind_iter())
            .bind(people.iter().map(|p| &p.birthdate).bind_iter())
            .execute(&mut conn)
            .await?
            .rows_affected();
    assert_eq!(rows_affected, 2);

    let p_query = sqlx::query_as::<_, Person>("select * from person order by id")
        .fetch_all(&mut conn)
        .await?;

    assert_eq!(people, p_query);
    Ok(())
}

#[sqlx_macros::test]
async fn test_pg_copy_chunked() -> anyhow::Result<()> {
    let mut conn = new::<Postgres>().await?;

    let mut row = "1".repeat(PG_COPY_MAX_DATA_LEN / 10 - 1);
    row.push_str("\n");

    // creates a payload with COPY_MAX_DATA_LEN + 1 as size
    let mut payload = row.repeat(10);
    payload.push_str("12345678\n");

    assert_eq!(payload.len(), PG_COPY_MAX_DATA_LEN + 1);

    let mut copy = conn.copy_in_raw("COPY products(name) FROM STDIN").await?;

    assert!(copy.send(payload.as_bytes()).await.is_ok());
    assert!(copy.finish().await.is_ok());
    Ok(())
}

async fn test_copy_in_error_case(query: &str, expected_error: &str) -> anyhow::Result<()> {
    let mut conn = new::<Postgres>().await?;
    conn.execute("CREATE TEMPORARY TABLE IF NOT EXISTS invalid_copy_target (id int4)")
        .await?;
    // Try the COPY operation
    match conn.copy_in_raw(query).await {