diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-03-20 20:23:06 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-03-20 20:24:44 +0100 |
commit | 9c3a341e79581541fc39ceddeec28daae7dc28cf (patch) | |
tree | a283c57d8917fcfd9fbed06c730b64b8c79e4504 | |
parent | cd6eba8b2b70404e93d9d4b0832faa7c9f00d217 (diff) | |
download | ramaskrik-social-9c3a341e79581541fc39ceddeec28daae7dc28cf.tar.gz ramaskrik-social-9c3a341e79581541fc39ceddeec28daae7dc28cf.tar.bz2 ramaskrik-social-9c3a341e79581541fc39ceddeec28daae7dc28cf.zip |
Pass database url into build_rocket helper function.
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | tests/room_tests.rs | 5 |
3 files changed, 9 insertions, 6 deletions
@@ -26,10 +26,7 @@ use std::collections::HashMap; use std::error::Error; use std::result::Result; -pub fn build_rocket() -> Result<rocket::Rocket, Box<dyn Error>> { - let db_url = dotenv::var("DATABASE_URL") - .map_err(|_| "No database! Set DATABASE_URL env var and try again.")?; - +pub fn build_rocket(db_url: &str) -> Result<rocket::Rocket, Box<dyn Error>> { let mut db_config = HashMap::new(); db_config.insert("url", rocket::config::Value::from(db_url)); diff --git a/src/main.rs b/src/main.rs index fdc8ff3..773fc66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,9 @@ use std::error::Error; use std::result::Result; fn main() -> Result<(), Box<dyn Error>> { - ramaskrik::build_rocket()?.launch(); + let db_url = dotenv::var("DATABASE_URL") + .map_err(|_| "No database! Set DATABASE_URL env var and try again.")?; + + ramaskrik::build_rocket(&db_url)?.launch(); Ok(()) } diff --git a/tests/room_tests.rs b/tests/room_tests.rs index c91519d..292954a 100644 --- a/tests/room_tests.rs +++ b/tests/room_tests.rs @@ -21,7 +21,10 @@ use rocket::http::ContentType; #[test] fn getting_rooms_from_api() { - let server = ramaskrik::build_rocket().unwrap(); + let db_url = dotenv::var("DATABASE_URL") + .map_err(|_| "No database! Set DATABASE_URL env var and try again.").unwrap(); + + let server = ramaskrik::build_rocket(&db_url).unwrap(); let client = rocket::local::Client::new(server).unwrap(); let mut response = client.get("/rooms").dispatch(); assert_eq!(response.content_type(), Some(ContentType::JSON)); |