Skip to content

Commit

Permalink
Add deref test
Browse files Browse the repository at this point in the history
  • Loading branch information
tcmulcahy committed Apr 15, 2024
1 parent 16ceafd commit 8f0c6f7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,44 @@ fn test_multi() {
}
assert!(items.is_empty());
}

// Tests the deref API variants - regression test for
// https://github.com/Stebalien/xattr/issues/57
#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
fn test_path_deref() {
use std::os::unix::ffi::OsStrExt;
// Only works on "real" filesystems.
let tmp = NamedTempFile::new_in("/var/tmp").unwrap();
assert!(xattr::get_deref(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);

xattr::set_deref(tmp.path(), "user.test", b"my test").unwrap();
assert_eq!(
xattr::get_deref(tmp.path(), "user.test").unwrap().unwrap(),
b"my test"
);
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.collect::<Vec<_>>(),
vec![OsStr::new("user.test")]
);

xattr::remove_deref(tmp.path(), "user.test").unwrap();
assert!(xattr::get_deref(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
}

0 comments on commit 8f0c6f7

Please sign in to comment.