ic-query-cli 0.102.0

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

#[test]
fn usage_describes_bounded_native_reports() {
    let text = render_help(command());
    assert!(text.starts_with("Inspect native IC system-canister metadata"));
    assert!(text.contains("Usage: system [COMMAND]"));
    assert!(text.contains("xdr"));
    assert!(text.contains("cycles"));

    for text in [
        render_help(report_command("xdr")),
        render_help(report_command("cycles")),
    ] {
        assert!(text.contains("--source-endpoint <url>"));
        assert!(text.contains("--json"));
        assert!(text.contains(COLLECTION_MODE_LIVE));
    }
}

#[tokio::test(flavor = "current_thread")]
async fn help_and_version_do_not_make_live_calls() {
    for args in [
        &["system", "--help"][..],
        &["system", "xdr", "--help"],
        &["system", "cycles", "--help"],
        &["system", "--version"],
    ] {
        assert!(crate::run(args.iter().map(OsString::from)).await.is_ok());
    }
}

#[test]
fn report_options_default_to_mainnet_and_native_endpoint() {
    let matches = parse_matches(&mut report_command("xdr"), Vec::<OsString>::new())
        .expect("parse default CMC options");

    assert_eq!(
        matches
            .get_one::<String>(SOURCE_ENDPOINT_ARG)
            .expect("validated source endpoint"),
        DEFAULT_CMC_SOURCE_ENDPOINT
    );
    assert_eq!(
        OutputFormat::from_json(matches.get_flag("json")),
        crate::cli::common::OutputFormat::Text
    );
}

fn report_command(name: &str) -> ClapCommand {
    command()
        .find_subcommand(name)
        .expect("declared system operation")
        .clone()
}