-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from torrust/testing/database-trait
Add integration tests for `Database` trait
- Loading branch information
Showing
16 changed files
with
325 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### Running Tests | ||
Torrust requires Docker to run different database systems for testing. [install docker here](https://docs.docker.com/engine/). | ||
|
||
Start the databases with `docker-compose` before running tests: | ||
|
||
$ docker-compose up | ||
|
||
Run all tests using: | ||
|
||
$ cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::future::Future; | ||
use torrust_index_backend::databases::database::{connect_database, Database, DatabaseDriver}; | ||
|
||
mod mysql; | ||
mod tests; | ||
mod sqlite; | ||
|
||
// used to run tests with a clean database | ||
async fn run_test<'a, T, F>(db_fn: T, db: &'a Box<dyn Database>) | ||
where | ||
T: FnOnce(&'a Box<dyn Database>) -> F + 'a, | ||
F: Future<Output = ()> | ||
{ | ||
// cleanup database before testing | ||
assert!(db.delete_all_database_rows().await.is_ok()); | ||
|
||
// run test using clean database | ||
db_fn(db).await; | ||
} | ||
|
||
// runs all tests | ||
pub async fn run_tests(db_driver: DatabaseDriver, db_path: &str) { | ||
let db = connect_database(&db_driver, db_path).await; | ||
|
||
run_test(tests::it_can_add_a_user, &db).await; | ||
run_test(tests::it_can_add_a_torrent_category, &db).await; | ||
run_test(tests::it_can_add_a_torrent, &db).await; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use torrust_index_backend::databases::database::{DatabaseDriver}; | ||
use crate::databases::{run_tests}; | ||
|
||
const DATABASE_URL: &str = "mysql://root:password@localhost:3306/torrust-index_test"; | ||
|
||
#[tokio::test] | ||
async fn run_mysql_tests() { | ||
run_tests(DatabaseDriver::Mysql, DATABASE_URL).await; | ||
} | ||
|
||
|
Oops, something went wrong.