Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Commiting the primary key test, expecting a build failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
chotchki committed Sep 3, 2021
1 parent 795a561 commit 81aa29d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/sql_primary_key_insert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use tokio_postgres::{SimpleQueryMessage, SimpleQueryRow};

mod common;

#[tokio::test]
async fn primary_key_insert() -> Result<(), Box<dyn std::error::Error>> {
let (request_shutdown, client) = common::_create_server_and_client().await?;
client
.batch_execute(
"create table foo (
bar text not null primary key,
baz text not null,
another text null)",
)
.await?;

client
.batch_execute("insert into foo (bar, baz, another) values('one', 'two', 'three')")
.await?;

let rows = client
.simple_query("select bar, baz, another from foo;")
.await?;

let row_count = rows.into_iter().fold(0, |acc, x| -> usize {
if let SimpleQueryMessage::Row(_) = x {
return acc + 1;
} else {
acc
}
});

assert_eq!(row_count, 1);

let result = client
.batch_execute("insert into foo (bar, baz, another) values('one', 'two', 'three')")
.await;
assert!(result.is_err());

common::_request_shutdown(request_shutdown).await
}

0 comments on commit 81aa29d

Please sign in to comment.