From c517113849ccac1206abe430757afb4a6851f03e Mon Sep 17 00:00:00 2001 From: Jonathan Rainer Date: Wed, 5 Jun 2024 14:45:37 +0100 Subject: [PATCH] Add a test to ensure we get the right socket name back (#1918) As per title, in some future dependency upgrades we change how we derive the socket name. We want to ensure behaviours are maintained as we upgrade. So this adds a test that checks the required behaviour so we can utilise it later when making changes. --- src/command/dev/router/config.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/command/dev/router/config.rs b/src/command/dev/router/config.rs index 80ad958e2..9b1ea47f0 100644 --- a/src/command/dev/router/config.rs +++ b/src/command/dev/router/config.rs @@ -303,3 +303,32 @@ impl RouterConfigReader { } } } + +#[cfg(test)] +mod tests { + use std::net::{IpAddr, Ipv4Addr}; + + use rstest::rstest; + + use crate::command::dev::router::RouterConfigHandler; + + #[rstest] + // This test is deliberately platform specific as it leans into how the OS handles sockets + // as such all these tests will run in a flavour of our CI pipeline but they may well not all + // run on a dev laptop + #[cfg_attr(target_os = "windows", ignore)] + #[case("/tmp/supergraph-127.0.0.1:4000.sock")] + #[cfg_attr(target_os = "linux", ignore)] + #[cfg_attr(target_os = "macos", ignore)] + #[case("@supergraph-127.0.0.1:4000.sock")] + fn test_socket_types_correctly_detected(#[case] expected_ipc_address: String) { + let ip_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); + let port_number = 4000; + let r_config = RouterConfigHandler::new(None, Some(ip_addr), Some(port_number)) + .expect("failed to create config handler"); + assert_eq!( + r_config.get_ipc_address().expect("should not fail"), + format!("{}", expected_ipc_address) + ); + } +}