ic-query-cli 0.104.1

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
use super::*;
use crate::cli::clap::parsed_options;
use crate::cli::{
    clap::{parse_matches, render_help},
    common::OutputFormat,
};
use std::ffi::OsString;

#[test]
fn help_discloses_type4_scope_authority_and_bounds() {
    let namespace = render_help(command());
    assert!(namespace.contains("Usage: node [COMMAND]"));
    assert!(namespace.contains("info"));
    assert!(namespace.contains("list"));

    let info = render_help(
        command()
            .find_subcommand("info")
            .expect("declared info operation")
            .clone(),
    );
    assert!(info.contains("<node-id>"));
    assert!(info.contains("requires the"));
    assert!(info.contains("returned reward type to be Type4"));
    assert!(info.contains("uncertified"));

    let list = render_help(
        command()
            .find_subcommand("list")
            .expect("declared list operation")
            .clone(),
    );
    assert!(list.contains("explicit Type4"));
    assert!(list.contains("all four currently documented statuses"));
    assert!(list.contains("10,000"));
    assert!(list.contains("--node-provider-id <principal>"));
}

#[test]
fn list_options_preserve_provider_endpoint_and_format() {
    let matches = parse_matches(
        &mut command()
            .find_subcommand("list")
            .expect("declared list operation")
            .clone(),
        [
            "--node-provider-id",
            "bvcsg-3od6r-jnydw-eysln-aql7w-td5zn-ay5m6-sibd2-jzojt-anwag-mqe",
            "--json",
            "--source-endpoint",
            "https://example.com/api/v3",
        ]
        .into_iter()
        .map(OsString::from),
    )
    .expect("parse Type4 node list options");

    let options: NodeListOptions = parsed_options(&matches);
    let (format, dashboard) = options.source.into_dashboard_request(42);
    assert_eq!(dashboard.source_endpoint, "https://example.com/api/v3");
    assert_eq!(
        options.node_provider_id.as_deref(),
        Some("bvcsg-3od6r-jnydw-eysln-aql7w-td5zn-ay5m6-sibd2-jzojt-anwag-mqe")
    );
    assert_eq!(format, OutputFormat::Json);
}

fn command() -> clap::Command {
    NodeCommand::augment_subcommands(clap::Command::new("node"))
}