Crates.io | sqlx-database-tester |
lib.rs | sqlx-database-tester |
version | 0.4.2 |
source | src |
created_at | 2021-08-20 08:17:12.748473 |
updated_at | 2022-09-06 05:28:53.833362 |
description | Library for creation of unit / integration tests with sqlx database support |
homepage | |
repository | |
max_upload_size | |
id | 439917 |
size | 52,358 |
This library makes it possible to create rust test cases for unit / integration testing with database access to unique databases per test case.
Each database is created with the database name generated as UUID v4, to prevent any collision between test cases.
The sqlx database pool variable of requested name is exposed to the test function scope.
The macro allows for creation and exposure of multiple databases per test function if needed.
DATABASE_URL
with a proper postgresql connection URI.
If .env
exists, it will be used through the dotenv
crate. (if it contains the database name, it will be used for a temporary database name prefix in form of <PFX>_<UUID>
).runtime-actix
or runtime-tokio
for use of respective runtimes#[sqlx_database_tester::test(
pool(variable = "default_migrated_pool"),
pool(variable = "migrated_pool", migrations = "./test_migrations"),
pool(variable = "empty_db_pool",
transaction_variable = "empty_db_transaction",
skip_migrations),
)]
async fn test_server_start() {
let migrated_pool_tables = sqlx::query!("SELECT * FROM pg_catalog.pg_tables")
.fetch_all(&migrated_pool)
.await
.unwrap();
let empty_pool_tables = sqlx::query!("SELECT * FROM pg_catalog.pg_tables")
.fetch_all(&empty_db_pool)
.await
.unwrap();
println!("Migrated pool tables: \n {:#?}", migrated_pool_tables);
println!("Empty pool tables: \n {:#?}", empty_pool_tables);
}
variable
: Variable of the PgPool to be exposed to the function scope (mandatory)transaction_variable
: If present, starts a new transaction and exposes variable of this name to the function scopemigrations
: Path to SQLX migrations directory for the specified pool (falls back to default ./migrations directory if left out)skip_migrations
: If present, doesn't run any migrationspip install --user pre-commit
pre-commit autoupdate
to update the pre-commit config to use the newest templatepre-commit install
to install the pre-commit hooks to your local environmentThis project is part of the source code of Famedly.
We think that software for healthcare should be open source, so we publish most parts of our source code at gitlab.com/famedly.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
For licensing information of this project, have a look at the LICENSE file within the repository.
If you compile the open source software that we make available to develop your own mobile, desktop or embeddable application, and cause that application to connect to our servers for any purposes, you have to aggree to our Terms of Service. In short, if you choose to connect to our servers, certain restrictions apply as follows:
No license is granted to the Famedly trademark and its associated logos, all of which will continue to be owned exclusively by Famedly GmbH. Any use of the Famedly trademark and/or its associated logos is expressly prohibited without the express prior written consent of Famedly GmbH.
For more information take a look at Famedly.com or contact us by info@famedly.com