mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-26 07:39:58 +00:00
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:
committed by
Heikki Linnakangas
parent
d9a1329834
commit
e0ee138a8b
1
test_runner/pg_clients/rust/tokio-postgres/.dockerignore
Normal file
1
test_runner/pg_clients/rust/tokio-postgres/.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target/
|
||||||
1
test_runner/pg_clients/rust/tokio-postgres/.gitignore
vendored
Normal file
1
test_runner/pg_clients/rust/tokio-postgres/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target/
|
||||||
1006
test_runner/pg_clients/rust/tokio-postgres/Cargo.lock
generated
Normal file
1006
test_runner/pg_clients/rust/tokio-postgres/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
test_runner/pg_clients/rust/tokio-postgres/Cargo.toml
Normal file
17
test_runner/pg_clients/rust/tokio-postgres/Cargo.toml
Normal 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]
|
||||||
6
test_runner/pg_clients/rust/tokio-postgres/Dockerfile
Normal file
6
test_runner/pg_clients/rust/tokio-postgres/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
FROM rust:1.67
|
||||||
|
WORKDIR /source
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN cargo build
|
||||||
|
CMD ["/source/target/debug/rust-neon-example"]
|
||||||
43
test_runner/pg_clients/rust/tokio-postgres/src/main.rs
Normal file
43
test_runner/pg_clients/rust/tokio-postgres/src/main.rs
Normal 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(())
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ from fixtures.utils import subprocess_capture
|
|||||||
[
|
[
|
||||||
"csharp/npgsql",
|
"csharp/npgsql",
|
||||||
"java/jdbc",
|
"java/jdbc",
|
||||||
|
"rust/tokio-postgres",
|
||||||
"python/asyncpg",
|
"python/asyncpg",
|
||||||
"python/pg8000",
|
"python/pg8000",
|
||||||
pytest.param(
|
pytest.param(
|
||||||
|
|||||||
Reference in New Issue
Block a user