use clap::Parser;
use midenup::commands::Midenup;
mod common;
use common::*;
#[test]
fn integration_install_uninstall_test() {
let test_name = "integration_install_uninstall_test";
let test_env = environment_setup(test_name);
const FILE: &str =
full_path_manifest!("tests/data/integration_install_uninstall_test/channel-manifest.json");
let (mut local_manifest, config) = test_setup(&test_env, FILE);
let toolchain_dir = test_env.midenup_home.join("toolchains");
let command = Midenup::try_parse_from(["midenup", "init"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to initialize");
assert!(test_env.midenup_home.exists());
assert!(toolchain_dir.exists());
assert!(test_env.cargo_home.join("bin").join("miden").exists());
let command = Midenup::try_parse_from(["midenup", "install", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable");
let latest_toolchain = toolchain_dir.join("0.16.0");
assert!(latest_toolchain.exists());
let stable_dir = toolchain_dir.join("stable");
assert!(stable_dir.exists());
assert!(stable_dir.is_symlink());
let stable_toolchain = std::fs::read_link(&stable_dir).expect("Failed to read stable symlink");
assert_eq!(stable_toolchain.file_name(), latest_toolchain.file_name());
let command = Midenup::try_parse_from(["midenup", "install", "0.15.0"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install 0.15.0");
let older_toolchain = toolchain_dir.join("0.15.0");
assert!(older_toolchain.exists());
assert!(stable_dir.exists());
assert!(latest_toolchain.exists());
let installed_toolchains = ["0.15.0", "0.16.0"].iter().map(|version| {
semver::Version::parse(version)
.unwrap_or_else(|_| panic!("Failed to turn {version} into semver::Version"))
});
local_manifest
.get_channels()
.map(|channel| channel.name.clone())
.eq(installed_toolchains);
let command = Midenup::try_parse_from(["midenup", "uninstall", "0.16.0"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to uninstall 0.16.0");
assert!(!latest_toolchain.exists());
assert!(!stable_dir.exists());
assert!(older_toolchain.exists());
let installed_toolchains = ["0.15.0"].iter().map(|version| {
semver::Version::parse(version)
.unwrap_or_else(|_| panic!("Failed to turn {version} into semver::Version"))
});
local_manifest
.get_channels()
.map(|channel| channel.name.clone())
.eq(installed_toolchains);
}