use super::*;
#[test]
fn terminal_paths_include_the_system_file_and_sorted_path_files() {
let root = crate::test_os::tempdir();
let system = root.path().join("etc");
let base = root.path().join("system-bin");
let first = root.path().join("first-bin");
let last = root.path().join("last-bin");
fs::create_dir_all(system.join("paths.d")).unwrap();
fs::write(
system.join("paths"),
format!("{}\n\n", crate::platform::path_text(&base)),
)
.unwrap();
fs::write(
system.join("paths.d/z-last"),
format!("{}\n", crate::platform::path_text(&last)),
)
.unwrap();
fs::write(
system.join("paths.d/a-first"),
format!("{}\n", crate::platform::path_text(&first)),
)
.unwrap();
assert_eq!(terminal_paths(&system).unwrap(), [base, first, last]);
}
#[test]
fn registration_respects_existing_install_repairs_moves_and_remembers_declines() {
let root = crate::test_os::tempdir();
let first = root.path().join("First.app/Contents/MacOS");
let moved = root.path().join("Moved.app/Contents/MacOS");
let state = root.path().join("state");
let paths = root.path().join("paths.d/artifactize");
fs::create_dir_all(&first).unwrap();
fs::create_dir_all(paths.parent().unwrap()).unwrap();
for command in ["artifactize", "artifactize-tools"] {
fs::write(first.join(command), "bundled command").unwrap();
}
register(&first, &paths, &state, true, |_, _| {
panic!("already reachable")
})
.unwrap();
assert!(!paths.exists());
register(&first, &paths, &state, false, |path, content| {
fs::write(path, content)?;
Ok(Consent::Installed)
})
.unwrap();
assert_eq!(
fs::read_to_string(&paths).unwrap(),
format!("{}\n", crate::platform::path_text(&first))
);
fs::create_dir_all(moved.parent().unwrap()).unwrap();
fs::rename(&first, &moved).unwrap();
register(&moved, &paths, &state, false, |path, content| {
fs::write(path, content)?;
Ok(Consent::Installed)
})
.unwrap();
assert_eq!(
fs::read_to_string(&paths).unwrap(),
format!("{}\n", crate::platform::path_text(&moved))
);
fs::remove_file(&paths).unwrap();
register(&moved, &paths, &state, false, |_, _| Ok(Consent::Declined)).unwrap();
let declined = fs::read(state.join("desktop-cli-declined.json")).unwrap();
assert_eq!(
serde_json::from_slice::<Vec<String>>(&declined).unwrap(),
[crate::platform::path_text(&moved)]
);
register(&moved, &paths, &state, false, |_, _| {
panic!("declined for this bundle")
})
.unwrap();
assert!(!paths.exists());
fs::create_dir_all(&first).unwrap();
for command in ["artifactize", "artifactize-tools"] {
fs::write(first.join(command), "bundled command").unwrap();
}
register(&first, &paths, &state, false, |path, content| {
fs::write(path, content)?;
Ok(Consent::Installed)
})
.unwrap();
assert_eq!(
fs::read_to_string(&paths).unwrap(),
format!("{}\n", crate::platform::path_text(&first))
);
}