helm-rs 0.1.0

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
use crate::cli::CliCommand;
use crate::cli::testing::{Row, check};
use crate::command::{SearchHub, SearchRepo};
use crate::error::Error;

const HUB: &str = include_str!("../../../tests/fixtures/commands/search/hub.json");
const ALL: &str = include_str!("../../../tests/fixtures/commands/search/search-all.json");
const VERSIONS: &str =
    include_str!("../../../tests/fixtures/commands/search/search-demo-versions.json");

#[test]
fn search_hub_maps_every_flag() {
    let table: Vec<Row<SearchHub>> = vec![
        (SearchHub::default(), &["search", "hub", "-o", "json"], None),
        (
            SearchHub {
                keyword: Some("nginx".into()),
                endpoint: Some("https://hub.example.com".into()),
                fail_on_no_result: true,
            },
            &[
                "search",
                "hub",
                "nginx",
                "-o",
                "json",
                "--endpoint",
                "https://hub.example.com",
                "--fail-on-no-result",
            ],
            None,
        ),
    ];

    check(table);
}

#[test]
fn search_repo_maps_every_flag() {
    let table: Vec<Row<SearchRepo>> = vec![
        (
            SearchRepo::default(),
            &["search", "repo", "-o", "json"],
            None,
        ),
        (
            SearchRepo {
                keyword: Some("web".into()),
                devel: true,
                fail_on_no_result: true,
                regexp: true,
                version: Some(">=1.0.0".into()),
                versions: true,
            },
            &[
                "search",
                "repo",
                "web",
                "-o",
                "json",
                "--devel",
                "--fail-on-no-result",
                "--regexp",
                "--version",
                ">=1.0.0",
                "--versions",
            ],
            None,
        ),
    ];

    check(table);
}

#[test]
fn hub_results_are_parsed_from_a_real_capture() {
    let hub = SearchHub::default();
    let charts = hub.parse(HUB.to_owned()).expect("parses");

    assert_eq!(charts.len(), 3);
    assert!(
        charts[0]
            .url
            .starts_with("https://artifacthub.io/packages/helm/")
    );
    assert_ne!(charts[0].version.len(), 0);
    assert_eq!(charts[0].repository.name, "rvvg-ingress-nginx");
    assert!(charts[0].repository.url.starts_with("oci://"));
    assert_eq!(hub.parse("[]".to_owned()).expect("empty").len(), 0);
    assert!(matches!(
        hub.parse("{}".to_owned()),
        Err(Error::Parse { .. })
    ));
}

#[test]
fn repo_results_are_parsed_from_real_captures() {
    let search = SearchRepo::default();
    let all = search.parse(ALL.to_owned()).expect("parses");
    let versions = search.parse(VERSIONS.to_owned()).expect("parses");

    assert_eq!(all.len(), 4);
    assert_eq!(all[3].name, "stable/other");
    assert_eq!(all[3].app_version, "2.5");
    assert_eq!(
        all[3].description,
        "A deprecated chart with the full metadata"
    );
    assert_eq!(versions.len(), 6);
    assert_eq!(versions[1].version, "0.1.0");
    assert!(matches!(
        search.parse("x".to_owned()),
        Err(Error::Parse { .. })
    ));
}