Skip to content

Commit

Permalink
refactor: [torrust#852] eenrich field types in HealthCheckApi config …
Browse files Browse the repository at this point in the history
…struct
  • Loading branch information
josecelano authored and da2ce7 committed Jun 19, 2024
1 parent 571b98b commit f3e5cb5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 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
2 changes: 1 addition & 1 deletion src/bootstrap/jobs/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::servers::service::Service;
#[allow(clippy::async_yields_async)]
#[instrument(ret, fields(registar = %registar))]
pub async fn start_job(config: &HealthCheckApi, registar: &Registar, version: Version) -> JoinHandle<()> {
let addr = config.bind_address.parse().expect("it should parse the binding address");
let addr = config.bind_address;

let form = registar.form();
let registry = registar.as_ref().clone();
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 @@ -23,10 +23,7 @@ impl Environment {
pub async fn new(config: &Arc<HealthCheckApi>, registar: &Registar) -> Self {
let registry = registar.as_ref().clone();

let addr = config
.bind_address
.parse::<std::net::SocketAddr>()
.expect("it should have a valid http tracker bind address");
let addr = config.bind_address;

let form = registar.form();

Expand Down

0 comments on commit f3e5cb5

Please sign in to comment.