Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Use configuration to connect to db
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianEffe committed Jul 22, 2023
1 parent 09ba006 commit de0d665
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Tests/full_url.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit de0d665

Please sign in to comment.