Skip to content

Commit

Permalink
Adding warning log to the database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
onihilist committed Oct 31, 2024
1 parent f34b363 commit 34aca58
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/database/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ pub async fn connectToDB() -> Result<tokio_postgres::Client, tokio_postgres::Err
Ok(client)
}
Err(e) => {
let error_message = format!("Impossible to connect to the database : {}", e);
let logs = utils::Logs::initLog(None, error_message, None);
let mut logs = utils::Logs::initLog(
None,
format!("Impossible to connect to the database : {}", e),
None
);
utils::Logs::error(logs);
logs = utils::Logs::initLog(
None,
format!("The server can run without the database, but all the informations will be not saved !"),
None);
utils::Logs::warning(logs);
Err(e)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod utils;
mod server;
mod database;
mod config;
mod tests;

use std::env;

Expand Down
24 changes: 24 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#[cfg(test)]
mod tests {

use std::process::Command;
use crate::server::startServer;

#[tokio::test]
async fn test_serverStart() {
startServer().await;
}

#[tokio::test]
async fn test_dbconnect() {
startServer().await;
// curl telnet://127.0.0.1:42000 <<< INIT_CONNECTION::onhlt::server::test
Command::new("C:/Windows/System32/curl")
.arg("telnet://127.0.0.1:42000")
.arg("<<<")
.arg("INIT_CONNECTION::onhlt::server::test")
.spawn()
.expect("ls command failed to start");
}
}

0 comments on commit 34aca58

Please sign in to comment.