Improved get_temp_db helper func.
This commit is contained in:
parent
dce7fc1468
commit
3b4acf9fc3
@ -16,7 +16,8 @@ test:stable:
|
|||||||
script:
|
script:
|
||||||
- rustc --version && cargo --version # Print version info for debugging
|
- rustc --version && cargo --version # Print version info for debugging
|
||||||
- cargo build --all
|
- cargo build --all
|
||||||
- cargo test --all --verbose --jobs 1
|
# - cargo test --all --verbose --jobs 1
|
||||||
|
- cargo test --all --verbose
|
||||||
|
|
||||||
# Use cargo to test the project
|
# Use cargo to test the project
|
||||||
test:nightly:
|
test:nightly:
|
||||||
@ -26,8 +27,7 @@ test:nightly:
|
|||||||
script:
|
script:
|
||||||
- rustc --version && cargo --version # Print version info for debugging
|
- rustc --version && cargo --version # Print version info for debugging
|
||||||
- cargo build
|
- cargo build
|
||||||
# - cargo test --verbose
|
- cargo test --verbose
|
||||||
# # Don't paralize, At least until I fix tempdb helper fn.
|
# - cargo test --verbose --jobs 1
|
||||||
- cargo test --verbose --jobs 1
|
|
||||||
# - cargo bench
|
# - cargo bench
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|||||||
@ -20,3 +20,4 @@ dotenv = "*"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.5"
|
tempdir = "0.3.5"
|
||||||
|
rand = "0.3.16"
|
||||||
@ -211,8 +211,11 @@ fn refresh_source(
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
|
extern crate rand;
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use rss;
|
use rss;
|
||||||
|
use self::rand::Rng;
|
||||||
|
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -229,11 +232,11 @@ mod tests {
|
|||||||
|
|
||||||
/// Create and return a Temporary DB.
|
/// Create and return a Temporary DB.
|
||||||
/// Will be destroed once the returned variable(s) is dropped.
|
/// Will be destroed once the returned variable(s) is dropped.
|
||||||
// TODO: make it an Iterator so it will give a unique db_path each time.
|
|
||||||
// And will also be able to run tests in parallel.
|
|
||||||
fn get_temp_db() -> TempDB {
|
fn get_temp_db() -> TempDB {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let tmp_dir = tempdir::TempDir::new("hammond_unit_test").unwrap();
|
let tmp_dir = tempdir::TempDir::new("hammond_unit_test").unwrap();
|
||||||
let db_path = tmp_dir.path().join("foo_tests.db");
|
let db_path = tmp_dir.path().join(format!("hammonddb_{}.db", rng.gen::<usize>()));
|
||||||
|
|
||||||
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
||||||
::run_migration_on(&db).unwrap();
|
::run_migration_on(&db).unwrap();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user