use std::fs; use std::path::PathBuf; use alt_controller_image::archive::NativeTarWriter; use alt_controller_image::cli::{Cli, Command, run}; use alt_controller_image::manifest::{ArtifactManifest, PackageRecord}; use clap::Parser; use tempfile::tempdir; #[test] fn parses_plan_with_an_explicit_spec_path() { let cli = Cli::try_parse_from(["alt-controller-image", "plan", "--spec", "image.toml"]) .expect("plan command parses"); assert!(matches!( cli.command, Command::Plan { spec } if spec == PathBuf::from("image.toml") )); } #[test] fn parses_build_with_explicit_workspace_and_output_paths() { let cli = Cli::try_parse_from([ "alt-controller-image", "build", "--spec", "image.toml", "--workspace", "work", "--output", "out/image.tar", ]) .expect("build command parses"); assert!(matches!( cli.command, Command::Build { spec, workspace, output } if spec == PathBuf::from("image.toml") && workspace == PathBuf::from("work") && output == PathBuf::from("out/image.tar") )); } #[test] fn parses_inspect_with_an_explicit_artifact_path() { let cli = Cli::try_parse_from([ "alt-controller-image", "inspect", "--artifact", "out/image.tar", ]) .expect("inspect command parses"); assert!(matches!( cli.command, Command::Inspect { artifact } if artifact == PathBuf::from("out/image.tar") )); } #[test] fn parses_compare_with_explicit_artifact_paths() { let cli = Cli::try_parse_from([ "alt-controller-image", "compare", "--left", "legacy.tar", "--right", "native.tar", ]) .expect("compare command parses"); assert!(matches!( cli.command, Command::Compare { left, right } if left == PathBuf::from("legacy.tar") && right == PathBuf::from("native.tar") )); } #[test] fn compare_uses_companion_manifests_for_tar_artifacts() { let fixture = tempdir().expect("temporary directory"); let rootfs = fixture.path().join("rootfs"); fs::create_dir_all(&rootfs).expect("create rootfs"); let left = fixture.path().join("left.tar"); let right = fixture.path().join("right.tar"); NativeTarWriter::new() .write(&rootfs, &left) .expect("write left archive"); NativeTarWriter::new() .write(&rootfs, &right) .expect("write right archive"); ArtifactManifest::new( vec![PackageRecord::new("controller", "1.0")], vec![], None, vec![], vec![], ) .expect("left manifest") .write_beside(&left) .expect("write left companion manifest"); ArtifactManifest::new( vec![PackageRecord::new("controller", "2.0")], vec![], None, vec![], vec![], ) .expect("right manifest") .write_beside(&right) .expect("write right companion manifest"); let error = run(Cli { command: Command::Compare { left, right }, }) .expect_err("companion package difference must be reported"); assert!(error.to_string().contains("artifacts differ semantically")); }