Skip to content

Commit

Permalink
refactor: [#852] eenrich field types in HealthCheckApi config struct
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed May 10, 2024
1 parent a20c9d7 commit 384e9f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
6 changes: 4 additions & 2 deletions packages/configuration/src/v1/health_check_api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use serde::{Deserialize, Serialize};
use serde_with::serde_as;

Expand All @@ -9,13 +11,13 @@ pub struct HealthCheckApi {
/// The format is `ip:port`, for example `127.0.0.1:1313`. If you want to
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
/// system to choose a random port, use port `0`.
pub bind_address: String,
pub bind_address: SocketAddr,
}

impl Default for HealthCheckApi {
fn default() -> Self {
Self {
bind_address: String::from("127.0.0.1:1313"),
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1313),
}
}
}
4 changes: 2 additions & 2 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tracker configuration factories for testing.
use std::env;
use std::net::IpAddr;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use torrust_tracker_configuration::Configuration;
use torrust_tracker_primitives::TrackerMode;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn ephemeral() -> Configuration {

// Ephemeral socket address for Health Check API
let health_check_api_port = 0u16;
config.health_check_api.bind_address = format!("127.0.0.1:{}", &health_check_api_port);
config.health_check_api.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), health_check_api_port);

// Ephemeral socket address for UDP tracker
let udp_port = 0u16;
Expand Down
5 changes: 1 addition & 4 deletions src/bootstrap/jobs/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ use crate::servers::signals::Halted;
///
/// It would panic if unable to send the `ApiServerJobStarted` notice.
pub async fn start_job(config: &HealthCheckApi, register: ServiceRegistry) -> JoinHandle<()> {
let bind_addr = config
.bind_address
.parse::<std::net::SocketAddr>()
.expect("it should have a valid health check bind address");
let bind_addr = config.bind_address;

let (tx_start, rx_start) = oneshot::channel::<Started>();
let (tx_halt, rx_halt) = tokio::sync::oneshot::channel::<Halted>();
Expand Down
5 changes: 1 addition & 4 deletions tests/servers/health_check_api/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub struct Environment<S> {

impl Environment<Stopped> {
pub fn new(config: &Arc<HealthCheckApi>, registar: Registar) -> Self {
let bind_to = config
.bind_address
.parse::<std::net::SocketAddr>()
.expect("Tracker API bind_address invalid.");
let bind_to = config.bind_address;

Self {
registar,
Expand Down

0 comments on commit 384e9f8

Please sign in to comment.