mirror of
https://github.com/rwf2/Rocket.git
synced 2025-02-16 13:42:05 +00:00
Remove test bootstrapping.
This commit is contained in:
parent
d8ada552c9
commit
b9c3a5c64b
@ -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}"
|
|
@ -78,32 +78,27 @@ fn index(msg: Option<FlashMessage>, conn: DbConn) -> Template {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket() -> (Rocket, Option<DbConn>) {
|
fn run_db_migrations(rocket: Rocket) -> Result<Rocket, Rocket> {
|
||||||
let rocket = rocket::ignite()
|
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(DbConn::fairing())
|
||||||
.attach(AdHoc::on_attach("Database Migrations", |rocket| {
|
.attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
|
||||||
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)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.mount("/", StaticFiles::from("static/"))
|
.mount("/", StaticFiles::from("static/"))
|
||||||
.mount("/", routes![index])
|
.mount("/", routes![index])
|
||||||
.mount("/todo", routes![new, toggle, delete])
|
.mount("/todo", routes![new, toggle, delete])
|
||||||
.attach(Template::fairing());
|
.attach(Template::fairing())
|
||||||
|
|
||||||
let conn = match cfg!(test) {
|
|
||||||
true => DbConn::get_one(&rocket),
|
|
||||||
false => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
(rocket, conn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rocket().0.launch();
|
rocket().launch();
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,9 @@ impl Task {
|
|||||||
pub fn delete_with_id(id: i32, conn: &SqliteConnection) -> bool {
|
pub fn delete_with_id(id: i32, conn: &SqliteConnection) -> bool {
|
||||||
diesel::delete(all_tasks.find(id)).execute(conn).is_ok()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,12 @@ static DB_LOCK: Mutex<()> = Mutex::new(());
|
|||||||
macro_rules! run_test {
|
macro_rules! run_test {
|
||||||
(|$client:ident, $conn:ident| $block:expr) => ({
|
(|$client:ident, $conn:ident| $block:expr) => ({
|
||||||
let _lock = DB_LOCK.lock();
|
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 $client = Client::new(rocket).expect("Rocket client");
|
||||||
let $conn = db.expect("failed to get database connection for testing");
|
let $conn = db.expect("failed to get database connection for testing");
|
||||||
|
assert!(Task::delete_all(&$conn), "failed to delete all tasks for testing");
|
||||||
|
|
||||||
$block
|
$block
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -49,24 +49,6 @@ function ensure_trailing_whitespace_free() {
|
|||||||
fi
|
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..."
|
echo ":: Ensuring all crate versions match..."
|
||||||
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
||||||
|
|
||||||
@ -128,9 +110,6 @@ elif [ "$1" = "--core" ]; then
|
|||||||
|
|
||||||
popd > /dev/null 2>&1
|
popd > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
echo ":: Bootstrapping examples..."
|
|
||||||
bootstrap_examples
|
|
||||||
|
|
||||||
echo ":: Building and testing libraries..."
|
echo ":: Building and testing libraries..."
|
||||||
CARGO_INCREMENTAL=0 cargo test --all-features --all $@
|
CARGO_INCREMENTAL=0 cargo test --all-features --all $@
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user