From 81aa29db41a75974881147d9f43c1d3b2a5e33c5 Mon Sep 17 00:00:00 2001 From: Christopher Hotchkiss Date: Fri, 3 Sep 2021 16:27:28 -0400 Subject: [PATCH] Commiting the primary key test, expecting a build failure. --- tests/sql_primary_key_insert.rs | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/sql_primary_key_insert.rs diff --git a/tests/sql_primary_key_insert.rs b/tests/sql_primary_key_insert.rs new file mode 100644 index 0000000..3bb706f --- /dev/null +++ b/tests/sql_primary_key_insert.rs @@ -0,0 +1,41 @@ +use tokio_postgres::{SimpleQueryMessage, SimpleQueryRow}; + +mod common; + +#[tokio::test] +async fn primary_key_insert() -> Result<(), Box> { + 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 +}