Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/monetize

xtask/tests/fast_verb.rs

//! ★ **`cargo xtask fast --product <id>`** (A28 H14, lane N3): monetize's own fast verb. The
//! product named is looked up in the declared table ([`xtask::fast::PRODUCTS`]): its checkout
//! beside monetize builds the product's box rows, media and guest and runs THIS checkout's
//! monetize-fast (buy → lay → install → ready → terminate in rootless containers).

use std::path::Path;

use xtask::fast::{self, PRODUCTS};

fn args(v: &[&str]) -> Vec<String> {
    v.iter().map(|s| s.to_string()).collect()
}

#[test]
fn the_verb_names_its_product_and_refuses_one_it_has_no_estate_for() {
    let a = fast::parse(&args(&["--product", "holger"])).unwrap();
    assert_eq!((a.product.id, a.rest.len()), ("holger", 0));
    let a = fast::parse(&args(&["--product", "gunnar", "--budget-s", "300", "--no-build"])).unwrap();
    assert_eq!((a.product.id, a.rest.clone()), ("gunnar", args(&["--budget-s", "300", "--no-build"])), "the rest goes to the product's verb");
    let e = fast::parse(&args(&[])).unwrap_err();
    assert!(e.contains("--product") && e.contains("holger") && e.contains("gunnar"), "{e}");
    let e = fast::parse(&args(&["--product", "idun"])).unwrap_err();
    assert!(e.contains("[fast-product]") && e.contains("idun"), "{e}");
    assert!(fast::parse(&args(&["--product"])).is_err());
    // The Lake has no boxes of its own to lay yet: its bench is `cargo xtask bench lake`.
    assert!(fast::parse(&args(&["--product", "lake"])).unwrap_err().contains("cargo xtask bench lake"));
}

#[test]
fn the_product_verb_runs_in_its_checkout_beside_this_one() {
    let a = fast::parse(&args(&["--product", "holger", "--out", "/tmp/f"])).unwrap();
    let (dir, argv) = fast::command(Path::new("/c/monetize"), &a);
    assert_eq!(dir, Path::new("/c/holger"));
    assert_eq!(argv, args(&["cargo", "xtask", "fast", "--out", "/tmp/f"]));
    let a = fast::parse(&args(&["--product", "gunnar"])).unwrap();
    assert_eq!(fast::command(Path::new("/c/monetize"), &a).0, Path::new("/c/gunnar"));
}

#[test]
fn every_product_in_the_table_is_one_the_core_has_a_lifecycle_for() {
    // The table names checkouts, never box names: those are the product's facts.
    let ids: Vec<&str> = PRODUCTS.iter().map(|p| p.id).collect();
    assert_eq!(ids, ["holger", "gunnar"]);
}

#[test]
fn a_missing_checkout_is_a_loud_refusal() {
    let a = fast::parse(&args(&["--product", "holger"])).unwrap();
    let e = fast::run(Path::new("/nonexistent-n3/monetize"), &a).unwrap_err();
    assert!(e.contains("[fast-no-checkout]") && e.contains("holger"), "{e}");
}