1 unstable release

0.1.0 Mar 7, 2024

#622 in Testing

Download history 140/week @ 2024-03-03 18/week @ 2024-03-10 1/week @ 2024-03-17 23/week @ 2024-03-31 78/week @ 2024-04-07

101 downloads per month

MIT license

22KB
404 lines

temp-postgres

Easy temporary postgresql instance for unit tests.

Use the TempPostgres struct to get a tokio_postgres::Client that is connected to a temporary postgres instance. All state of the spawned postgres instance is stored in a temporary directory, which will be cleaned up automatically (unless disabled).

On Unix platforms, the client is connected over a Unix socket. Windows support is planned by picking a free TCP port on the loopback adapter.

Example

See the example in the repository for a more detailed example using assert2.

use temp_postgres::TempPostgres;

let postgres = TempPostgres::new().await?;
println!("Using temporary directory: {}", postgres.directory().display());

let client = postgres.client().await?;
client.execute("CREATE TABLE pets (name TEXT PRIMARY KEY, species TEXT)", &[]).await?;

License: MIT

lib.rs:

Easy temporary postgresql instance for unit tests.

Use the TempPostgres struct to get a tokio_postgres::Client that is connected to a temporary postgres instance. All state of the spawned postgres instance is stored in a temporary directory, which will be cleaned up automatically (unless disabled).

On Unix platforms, the client is connected over a Unix socket. Windows support is planned by picking a free TCP port on the loopback adapter.

Example

See the example in the repository for a more detailed example using assert2.

use temp_postgres::TempPostgres;

let postgres = TempPostgres::new().await?;
println!("Using temporary directory: {}", postgres.directory().display());

let client = postgres.client().await?;
client.execute("CREATE TABLE pets (name TEXT PRIMARY KEY, species TEXT)", &[]).await?;

Dependencies

~10–21MB
~389K SLoC