test(cli): add comprehensive tests for multi-target resolution and output
Add unit tests for target normalization and address family filtering, and expand integration tests to verify column rendering and CSV output for multiple targets. Update subscriber config to drop oldest events under backpressure for better CLI stability.
This commit is contained in:
1 parent
69fd24ce64
commit
2065fe5e11
3 files changed
+151
-1
No files matched your search
@@ -398,6 +398,57 @@ mod tests {
|
||||
assert_eq!(specs[1].label, "host-a:2112#2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_resolved_target_addresses_are_rejected() {
|
||||
let args = parse(&["127.0.0.1:2112", "127.0.0.1"]).unwrap();
|
||||
let err = args.resolved_managed_targets().unwrap_err();
|
||||
|
||||
assert!(err.contains("duplicate resolved target address 127.0.0.1:2112"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn target_normalization_matches_single_target_forms() {
|
||||
assert_eq!(normalize_target_addr("127.0.0.1"), "127.0.0.1:2112");
|
||||
assert_eq!(normalize_target_addr("127.0.0.1:1234"), "127.0.0.1:1234");
|
||||
assert_eq!(normalize_target_addr("example.com"), "example.com:2112");
|
||||
assert_eq!(
|
||||
normalize_target_addr("example.com:1234"),
|
||||
"example.com:1234"
|
||||
);
|
||||
assert_eq!(normalize_target_addr("[::1]"), "[::1]:2112");
|
||||
assert_eq!(normalize_target_addr("[::1]:1234"), "[::1]:1234");
|
||||
assert_eq!(normalize_target_addr("::1"), "[::1]:2112");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn target_resolution_respects_family_filters() {
|
||||
let config = ClientConfig::default();
|
||||
assert_eq!(
|
||||
resolve_cli_target("127.0.0.1", &config).unwrap(),
|
||||
"127.0.0.1:2112".parse().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_cli_target("[::1]", &config).unwrap(),
|
||||
"[::1]:2112".parse().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_cli_target("::1", &config).unwrap(),
|
||||
"[::1]:2112".parse().unwrap()
|
||||
);
|
||||
|
||||
let mut ipv4_only = ClientConfig::default();
|
||||
ipv4_only.socket_config.ipv4_only = true;
|
||||
assert!(resolve_cli_target("127.0.0.1", &ipv4_only)
|
||||
.unwrap()
|
||||
.is_ipv4());
|
||||
assert!(resolve_cli_target("::1", &ipv4_only).is_err());
|
||||
|
||||
let mut ipv6_only = ClientConfig::default();
|
||||
ipv6_only.socket_config.ipv6_only = true;
|
||||
assert!(resolve_cli_target("::1", &ipv6_only).unwrap().is_ipv6());
|
||||
assert!(resolve_cli_target("127.0.0.1", &ipv6_only).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_labelled_target_syntax_is_rejected() {
|
||||
assert!(parse(&["--target", "missing-equals"]).is_err());
|
||||
|
||||
@@ -285,7 +285,11 @@ fn run_group_stream(
|
||||
managed_targets,
|
||||
SubscriberConfig {
|
||||
capacity: 16_384,
|
||||
overflow: SubscriberOverflow::Disconnect,
|
||||
// CLI output is best-effort under sustained backpressure. Dropping
|
||||
// stale rows keeps continuous runs attached to the running group
|
||||
// instead of turning a full output queue into a disconnected
|
||||
// subscriber and a potentially blocking join.
|
||||
overflow: SubscriberOverflow::DropOldest,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user