1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! # Nafta
//!
//! Creates temporary SQLite database for testing using diesel.
//!
//! ```toml
//! [dev-dependencies]
//! nafta = "0.1"
//! ```
//!
//! # Minimal example
//!
//! ```rust
//! // Creates empty SQLite database in temporary folder
//! let test_db = nafta::sqlite::TestDb::new();
//! // Work with the conn
//! let conn = test_db.conn();
//!
//! // You can check that database is removed
//! let path = test_db.db_path.clone();
//! // Necessary to drop anything which can block file
//! drop(conn);
//! // Dropping `test_db` to check it was really removed
//! drop(test_db);
//! // sleep added due to problem on windows/github actions randomly failed #9
//! std::thread::sleep(std::time::Duration::from_millis(100));
//! assert!(!path.exists()); // Neccessary to test if path was removed
//! ```
//!
//! # Example with migration
//!
//! ```ignore
//! // Database
//! extern crate diesel;
//!
//! #[macro_use]
//! extern crate diesel_migrations;
//!
//! // This macro from `diesel_migrations` defines an `embedded_migrations` module
//! // containing a function named `run`. This allows the example to be run and
//! // tested without any outside setup of the database.
//! embed_migrations!("migrations");
//!
//! #[cfg(test)]
//! mod tests {
//!
//! #[test]
//! async fn test_get_user() {
//! let test_db = nafta::sqlite::TestDb::new();
//! let conn = test_db
//! .conn()
//! .expect("Not possible to get pooled connection");
//!
//! embedded_migrations::run(&conn).expect("Migration not possible to run");
//!
//! // Test
//! let all_user = db::users::get_all_users(test_db.pool);
//! assert!(all_user.is_ok());
//! }
//! }
//! ```