Skip to content

Commit

Permalink
test: add args parsing and domain resolution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lvillis committed Jan 14, 2024
1 parent f5a77c9 commit 4afca4c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/ref-type/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ fn main() {
eprintln!("value: {value}");

println!("::set-output name=value::{value}");
}
}
2 changes: 1 addition & 1 deletion bin/ref-type/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
34 changes: 32 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 4afca4c

Please sign in to comment.