aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs5
-rw-r--r--src/main.rs5
-rw-r--r--tests/room_tests.rs5
3 files changed, 9 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7929ab2..989a6ba 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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));