Crates.io | xsqlx-db-tester |
lib.rs | xsqlx-db-tester |
version | 0.1.3 |
source | src |
created_at | 2023-06-01 19:07:38.422769 |
updated_at | 2023-06-02 08:59:28.250382 |
description | A simple tool to test sqlx database, it automatically create and drop database when the test create and drop. |
homepage | https://github.com/laizhenxing/xsqlx-db-tester |
repository | https://github.com/laizhenxing/xsqlx-db-tester |
max_upload_size | |
id | 880034 |
size | 20,671 |
This project learns from: https://github.com/tyrchen/sqlx-db-tester/tree/master
This a tool test sqlx with postgres. It only support tokio runtime in this moment.
You should first create TestDB data structure in your tests. It will automcatically create a database and a connection pool for you. Then you could get the connection string or connection pool from it to use on your own code. When TestDB gets drop, it will automcatically drop the database.
#[tokio::test]
async fn some_test() {
let tdb = TestDB::new("postgers://postgrses:postgres@localhost:5432", "./migrations");
let pool = tdb.get_pool().await;
// do you test logic
// the code finish in this test, tdb will drop the database which it create.
}
Have fun with this crate!
This project is distributed under the terms of MIT license.