use super::*;
use crate::cli::clap::render_help;
#[test]
fn list_defaults_to_mainnet_ic_catalog() {
let (options_format, options_verbose, options) =
parse_test_options(subnet_operation("list"), &[], test_catalog_list_request)
.expect("parse list");
assert_eq!(options.cache.network, MAINNET_NETWORK);
assert_eq!(options_format, OutputFormat::Text);
assert_eq!(
catalog_endpoint(&options.read_policy),
DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT
);
assert_eq!(options.range_limit, 50);
assert!(!options_verbose);
}
#[test]
fn list_parses_filters_and_json_format() {
let (options_format, options_verbose, options) = parse_test_options(
subnet_operation("list"),
&[
"--kind",
"application",
"--specialization",
"fiduciary",
"--geo",
"global",
"--json",
"--show-ranges",
"--verbose",
"--range-limit",
"12",
],
test_catalog_list_request,
)
.expect("parse list");
assert_eq!(options.filters.kind, Some(SubnetKind::Application));
assert_eq!(
options.filters.specialization,
Some(SubnetSpecialization::Fiduciary)
);
assert_eq!(
options.filters.geographic_scope,
Some(GeographicScope::Global)
);
assert_eq!(options_format, OutputFormat::Json);
assert_eq!(
catalog_endpoint(&options.read_policy),
DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT
);
assert!(options.show_ranges);
assert!(options_verbose);
assert_eq!(options.range_limit, 12);
}
#[test]
fn clap_rejects_invalid_nns_option_values() {
assert!(matches!(
parse_test_options(
subnet_operation("list"),
&["--kind", "subnet"],
test_catalog_list_request,
),
Err(NnsCommandError::Usage(_))
));
assert!(matches!(
parse_test_options(
subnet_operation("list"),
&["--range-limit", "0"],
test_catalog_list_request,
),
Err(NnsCommandError::Usage(_))
));
assert!(matches!(
parse_test_options(
subnet_operation("info"),
&["aaaaa-aa", "--as", "route"],
test_catalog_info_request,
),
Err(NnsCommandError::Usage(_))
));
}
#[test]
fn info_usage_names_subnet_lookup_input() {
let text = render_help(subnet_operation("info"));
assert!(text.contains("subnet|canister|subnet-prefix"));
assert!(text.contains("unique subnet prefix"));
assert!(text.contains("icq nns subnet info <subnet-prefix>"));
assert!(text.contains("--as <subnet|canister>"));
}
#[test]
fn list_and_info_help_describe_cache_recovery() {
let list = render_help(subnet_operation("list"));
let info = render_help(subnet_operation("info"));
assert!(list.contains("Collection mode: Cache-backed read"));
assert!(info.contains("Collection mode: Cache-backed read"));
assert!(list.contains("missing or recoverably invalid"));
assert!(info.contains("missing or recoverably invalid"));
}
#[test]
fn refresh_parses_defaults_and_export_options() {
let options = parse_test_options(
subnet_operation("refresh"),
&[
"--json",
"--source-endpoint",
"https://icp-api.io",
"--dry-run",
"--output",
"catalog.preview.json",
],
parsed_arguments::<NnsLeafRefreshOptions>,
)
.expect("parse refresh");
assert_eq!(options.common.format(), OutputFormat::Json);
assert_eq!(options.common.source_endpoint, "https://icp-api.io");
assert!(options.dry_run);
assert_eq!(
options.output_path,
Some(PathBuf::from("catalog.preview.json"))
);
}
#[test]
fn refresh_is_advertised_as_subnet_command() {
let text = render_help(subnet_command());
let refresh = render_help(subnet_operation("refresh"));
assert!(text.contains("refresh"));
assert!(text.contains("Show observed operational status and fault-distance by Subnet"));
assert!(refresh.contains("icq nns subnet refresh"));
assert!(refresh.contains("Collection mode: Forced live refresh"));
}
#[test]
fn nns_namespace_help_mentions_subnet() {
let text = render_help(command());
assert!(text.contains("Inspect NNS metadata"));
assert!(text.contains("subnet"));
}
fn subnet_operation(name: &str) -> ClapCommand {
subnet_command()
.find_subcommand_mut(name)
.expect("declared subnet operation")
.clone()
}