use zipatch_rs::test_utils::{MAGIC, make_chunk};
use zipatch_rs::{ApplyError, ParseError, apply_patch_file};
#[test]
fn apply_patch_file_one_shot_creates_directory_on_install_root() {
let mut adir_body = Vec::new();
adir_body.extend_from_slice(&7u32.to_be_bytes());
adir_body.extend_from_slice(b"oneshot");
let mut patch = Vec::new();
patch.extend_from_slice(&MAGIC);
patch.extend_from_slice(&make_chunk(b"ADIR", &adir_body));
patch.extend_from_slice(&make_chunk(b"EOF_", &[]));
let tmp = tempfile::tempdir().unwrap();
let patch_path = tmp.path().join("oneshot.patch");
std::fs::write(&patch_path, &patch).unwrap();
let install_root = tmp.path().join("install");
std::fs::create_dir(&install_root).unwrap();
apply_patch_file(&patch_path, &install_root).expect("one-shot apply must succeed");
assert!(
install_root.join("oneshot").is_dir(),
"apply_patch_file must have created the directory under install_root"
);
}
#[test]
fn apply_patch_file_surfaces_parse_failure_as_apply_error_parse() {
let tmp = tempfile::tempdir().unwrap();
let missing = tmp.path().join("does_not_exist.patch");
let install_root = tmp.path();
let err = apply_patch_file(&missing, install_root).unwrap_err();
assert!(
matches!(err, ApplyError::Parse(ParseError::Io { .. })),
"missing patch file must surface as ApplyError::Parse(ParseError::Io), got {err:?}"
);
}