Add a test for tokio-postgres client to the driver test suite.

It is fully supported. To enable TLS, though, it requires some extra
glue code, and a dependency to a TLS library.
This commit is contained in:
Heikki Linnakangas
2023-03-13 11:11:01 +02:00
committed by Heikki Linnakangas
parent d9a1329834
commit e0ee138a8b
7 changed files with 1075 additions and 0 deletions

View File

@@ -0,0 +1 @@
target/

View File

@@ -0,0 +1 @@
target/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
[package]
name = "rust-neon-example"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
native-tls = "0.2.11"
postgres-native-tls = "0.5.0"
tokio = { version = "1.26", features=["rt", "macros"] }
tokio-postgres = "0.7.7"
# This is not part of the main 'neon' workspace
[workspace]

View File

@@ -0,0 +1,6 @@
FROM rust:1.67
WORKDIR /source
COPY . .
RUN cargo build
CMD ["/source/target/debug/rust-neon-example"]

View File

@@ -0,0 +1,43 @@
use std::env::VarError;
use tokio_postgres;
fn get_env(key: &str) -> String {
match std::env::var(key) {
Ok(val) => val,
Err(VarError::NotPresent) => panic!("{key} env variable not set"),
Err(VarError::NotUnicode(_)) => panic!("{key} is not valid unicode"),
}
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), tokio_postgres::Error> {
let host = get_env("NEON_HOST");
let database = get_env("NEON_DATABASE");
let user = get_env("NEON_USER");
let password = get_env("NEON_PASSWORD");
let url = format!("postgresql://{user}:{password}@{host}/{database}");
// Use the native TLS implementation (Neon requires TLS)
let tls_connector =
postgres_native_tls::MakeTlsConnector::new(native_tls::TlsConnector::new().unwrap());
// Connect to the database.
let (client, connection) = tokio_postgres::connect(&url, tls_connector).await?;
// The connection object performs the actual communication with the database,
// so spawn it off to run on its own.
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
}
});
let result = client.query("SELECT 1", &[]).await?;
let value: i32 = result[0].get(0);
assert_eq!(value, 1);
println!("{value}");
Ok(())
}

View File

@@ -13,6 +13,7 @@ from fixtures.utils import subprocess_capture
[
"csharp/npgsql",
"java/jdbc",
"rust/tokio-postgres",
"python/asyncpg",
"python/pg8000",
pytest.param(