1
0
Fork 0

Add tests

This commit is contained in:
Alex Kotov 2020-10-15 05:16:06 +05:00
parent fcbb6f1598
commit 8186c43c4d
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 38 additions and 11 deletions

View File

@ -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();
}

22
src/tests.rs Normal file
View File

@ -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);
}
}

12
src/web.rs Normal file
View File

@ -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())
}