use super::*;
#[test]
fn copies_survive_mount_removal_follow_updates_and_preserve_foreign_commands() {
let root = crate::test_os::tempdir();
let mount = root.path().join("mount/usr/bin");
let stable = root.path().join("data/artifactize/bin");
let local = root.path().join("home/.local/bin");
fs::create_dir_all(&mount).unwrap();
for name in COMMANDS {
fs::write(mount.join(name), format!("{name} old")).unwrap();
}
register(&mount, &stable, &local, "1", true).unwrap();
assert!(!local.exists());
register(&mount, &stable, &local, "1", false).unwrap();
fs::remove_dir_all(root.path().join("mount")).unwrap();
for name in COMMANDS {
assert_eq!(
fs::read_to_string(local.join(name)).unwrap(),
format!("{name} old")
);
}
fs::create_dir_all(&mount).unwrap();
for name in COMMANDS {
fs::write(mount.join(name), format!("{name} new")).unwrap();
}
register(&mount, &stable, &local, "2", true).unwrap();
for name in COMMANDS {
assert_eq!(
fs::read_to_string(local.join(name)).unwrap(),
format!("{name} new")
);
}
fs::remove_file(local.join("artifactize")).unwrap();
fs::write(local.join("artifactize"), "foreign installation").unwrap();
assert_eq!(
register(&mount, &stable, &local, "3", false)
.unwrap_err()
.kind(),
io::ErrorKind::AlreadyExists
);
assert_eq!(
fs::read_to_string(local.join("artifactize")).unwrap(),
"foreign installation"
);
assert_eq!(
fs::read_to_string(local.join("artifactize-tools")).unwrap(),
"artifactize-tools new"
);
}