tests: make xattr test more robust #1509
Open
+34
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the xattr test asserts that listxattr() on Cargo.toml returns a length of 0.
This causes a spurious failure when Cargo.toml does have xattrs, and this can happen in fairly normal situations like when a Linux distribution enables selinux (as it does on an AlmaLinux 10 test system, for example):
$ cat /etc/almalinux-release
AlmaLinux release 10.0 (Purple Lion)
$ getfattr -d -m - Cargo.toml
security.selinux=[...]
$ cargo test --features=fs,stdio xattr
[...]
thread 'xattr::xattr_basic' panicked at tests/fs/xattr.rs:88:5: assertion
left == right
failedleft: 17
right: 0
This change fixes the failure by making the test not assume that the file has no xattrs defined.
Given that, pretty much the only reasonable thing the test can assume about a call to listxattr is that it should succeed for a file that is known to exist. So this makes the test just assert that it succeeds.
Aside from how the above commit fixes this test, there are other methods that could be better:
Thoughts on either of those approaches? They would be more complicated but could offer better coverage.