diff --git a/bin/ref-type/src/main.rs b/bin/ref-type/src/main.rs index e751519..fb12499 100644 --- a/bin/ref-type/src/main.rs +++ b/bin/ref-type/src/main.rs @@ -22,4 +22,4 @@ fn main() { eprintln!("value: {value}"); println!("::set-output name=value::{value}"); -} \ No newline at end of file +} diff --git a/bin/ref-type/tests/integration.rs b/bin/ref-type/tests/integration.rs index 963ff83..33df68e 100644 --- a/bin/ref-type/tests/integration.rs +++ b/bin/ref-type/tests/integration.rs @@ -41,4 +41,4 @@ fn valid_version_with_lots_of_digits_is_release() { stdout("refs/tags/01232132.098327498374.43268473849734"), "::set-output name=value::release\n" ); -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 8a288af..bfeb2f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,13 +58,13 @@ fn main() { ctrlc::set_handler(move || { r.store(false, Ordering::SeqCst); }) - .expect("Error setting Ctrl-C handler"); + .expect("Error setting Ctrl-C handler"); if args.continuous { println!(); println!("** Pinging continuously. Press control-c to stop **"); - println!(); } + println!(); let mut successful_pings = 0; let mut total_duration = 0f64; @@ -120,4 +120,34 @@ fn main() { min_duration, avg_duration, max_duration ); } + println!(); +} + +#[cfg(test)] +mod tests { + use super::*; + use std::net::ToSocketAddrs; + + #[test] + fn test_args_parsing() { + let args = Args::parse_from("tcping 127.0.0.1:80 -c 5".split_whitespace()); + assert_eq!(args.address, "127.0.0.1:80"); + assert_eq!(args.count, 5); + assert!(!args.continuous); + } + + #[test] + fn test_args_parsing_with_continuous() { + let args = Args::parse_from("tcping 127.0.0.1:80 -t".split_whitespace()); + assert_eq!(args.address, "127.0.0.1:80"); + assert_eq!(args.count, 4); + assert!(args.continuous); + } + + #[test] + fn test_domain_name_resolution() { + let domain_name = "cloudflare.com:80"; + let socket_addrs = domain_name.to_socket_addrs(); + assert!(socket_addrs.is_ok(), "Failed to resolve domain name"); + } }