Add tests
This commit is contained in:
parent
fcbb6f1598
commit
8186c43c4d
15
src/main.rs
15
src/main.rs
|
@ -1,6 +1,9 @@
|
|||
#![feature(decl_macro, proc_macro_hygiene)]
|
||||
|
||||
#[cfg(test)] mod tests;
|
||||
|
||||
pub mod config;
|
||||
mod web;
|
||||
mod database;
|
||||
mod routes;
|
||||
mod schema;
|
||||
|
@ -13,17 +16,7 @@ mod forms;
|
|||
|
||||
extern crate rocket_contrib;
|
||||
|
||||
use rocket_contrib::templates::Template;
|
||||
|
||||
fn main() {
|
||||
let config = config::Config::default().unwrap();
|
||||
|
||||
rocket(config).launch();
|
||||
}
|
||||
|
||||
fn rocket(config: config::Config) -> rocket::Rocket {
|
||||
rocket::custom(config.to_rocket_config().unwrap())
|
||||
.manage(database::create_db_pool(config))
|
||||
.attach(Template::fairing())
|
||||
.mount("/", routes::routes())
|
||||
web::rocket(config).launch();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::config;
|
||||
use crate::web;
|
||||
|
||||
use rocket::http::Status;
|
||||
use rocket::local::Client;
|
||||
|
||||
fn client() -> Client {
|
||||
let config = config::Config::default().unwrap();
|
||||
let rocket = web::rocket(config);
|
||||
Client::new(rocket).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index() {
|
||||
let client = client();
|
||||
let response = client.get("/").dispatch();
|
||||
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::config;
|
||||
use crate::database;
|
||||
use crate::routes;
|
||||
|
||||
use rocket_contrib::templates::Template;
|
||||
|
||||
pub fn rocket(config: config::Config) -> rocket::Rocket {
|
||||
rocket::custom(config.to_rocket_config().unwrap())
|
||||
.manage(database::create_db_pool(config))
|
||||
.attach(Template::fairing())
|
||||
.mount("/", routes::routes())
|
||||
}
|
Reference in New Issue