Remove test bootstrapping.

This commit is contained in:
jeb 2018-12-30 13:52:08 -08:00 committed by Sergio Benitez
parent d8ada552c9
commit b9c3a5c64b
5 changed files with 25 additions and 49 deletions

View File

@ -1,6 +0,0 @@
#! /usr/bin/env bash
SCRIPT_PATH=$(cd "$(dirname "$0")" ; pwd -P)
DATABASE_URL="${SCRIPT_PATH}/db/db.sqlite"
rm -f "${DATABASE_URL}"

View File

@ -78,32 +78,27 @@ fn index(msg: Option<FlashMessage>, conn: DbConn) -> Template {
})
}
fn rocket() -> (Rocket, Option<DbConn>) {
let rocket = rocket::ignite()
.attach(DbConn::fairing())
.attach(AdHoc::on_attach("Database Migrations", |rocket| {
fn run_db_migrations(rocket: Rocket) -> Result<Rocket, Rocket> {
let conn = DbConn::get_one(&rocket).expect("database connection");
match embedded_migrations::run(&*conn) {
Ok(()) => Ok(rocket),
Err(e) => {
error!("Failed to run database migrations: {:?}", e);
Err(rocket)
},
}
}))
}
}
fn rocket() -> Rocket {
rocket::ignite()
.attach(DbConn::fairing())
.attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
.mount("/", StaticFiles::from("static/"))
.mount("/", routes![index])
.mount("/todo", routes![new, toggle, delete])
.attach(Template::fairing());
let conn = match cfg!(test) {
true => DbConn::get_one(&rocket),
false => None,
};
(rocket, conn)
.attach(Template::fairing())
}
fn main() {
rocket().0.launch();
rocket().launch();
}

View File

@ -50,4 +50,9 @@ impl Task {
pub fn delete_with_id(id: i32, conn: &SqliteConnection) -> bool {
diesel::delete(all_tasks.find(id)).execute(conn).is_ok()
}
#[cfg(test)]
pub fn delete_all(conn: &SqliteConnection) -> bool {
diesel::delete(all_tasks).execute(conn).is_ok()
}
}

View File

@ -16,9 +16,12 @@ static DB_LOCK: Mutex<()> = Mutex::new(());
macro_rules! run_test {
(|$client:ident, $conn:ident| $block:expr) => ({
let _lock = DB_LOCK.lock();
let (rocket, db) = super::rocket();
let rocket = super::rocket();
let db = super::DbConn::get_one(&rocket);
let $client = Client::new(rocket).expect("Rocket client");
let $conn = db.expect("failed to get database connection for testing");
assert!(Task::delete_all(&$conn), "failed to delete all tasks for testing");
$block
})
}

View File

@ -49,24 +49,6 @@ function ensure_trailing_whitespace_free() {
fi
}
function bootstrap_examples() {
while read -r file; do
bootstrap_script="${file}/bootstrap.sh"
if [ -x "${bootstrap_script}" ]; then
echo " Bootstrapping ${file}..."
env_vars=$(bash "${bootstrap_script}")
bootstrap_result=$?
if [ $bootstrap_result -ne 0 ]; then
echo " Running bootstrap script (${bootstrap_script}) failed!"
exit 1
else
eval $env_vars
fi
fi
done < <(find "${EXAMPLES_DIR}" -maxdepth 1 -type d)
}
echo ":: Ensuring all crate versions match..."
check_versions_match "${ALL_PROJECT_DIRS[@]}"
@ -128,9 +110,6 @@ elif [ "$1" = "--core" ]; then
popd > /dev/null 2>&1
else
echo ":: Bootstrapping examples..."
bootstrap_examples
echo ":: Building and testing libraries..."
CARGO_INCREMENTAL=0 cargo test --all-features --all $@
fi