From de0d66525e4c6606becee53b4f56b690a19ac6f5 Mon Sep 17 00:00:00 2001 From: Adrian Date: Sat, 22 Jul 2023 16:13:44 +0300 Subject: [PATCH] Use configuration to connect to db --- Tests/full_url.rs | 8 ++++++++ src/lib.rs | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Tests/full_url.rs b/Tests/full_url.rs index d01cd72..a11c05e 100644 --- a/Tests/full_url.rs +++ b/Tests/full_url.rs @@ -1,10 +1,18 @@ pub mod shared; +use briefly::configuration::get_configuration; use shared::test_app::TestApp; +use sqlx::{Connection, PgConnection}; #[tokio::test] async fn full_url_returns_200_for_valid_form_data() { let app = TestApp::new().await; + let configuration = get_configuration().expect("Failed to read configuration"); + let connection_string = configuration.database.connection_string(); + + let connection = PgConnection::connect(&connection_string) + .await + .expect("Failed to connect to Postgres"); let body = String::from("{\"url\":\"www.google.com\",\"extension\":\"google\"}"); let response = app.post("full_url", body).send().await.unwrap(); diff --git a/src/lib.rs b/src/lib.rs index f4b5621..d11983b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,12 +3,14 @@ pub mod routes; use axum::routing::{get, post}; use axum::Router; +use configuration::get_configuration; use routes::{full_url, health_check}; pub async fn run() { let app = app(); - - axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) + let configuration = get_configuration().expect("Failed to read configuration"); + let address = format!("127.0.0.1:{}", configuration.application_port); + axum::Server::bind(&address.parse().unwrap()) .serve(app.into_make_service()) .await .unwrap()