Skip to content

Commit

Permalink
Use proper temporary file in object_type_from_fd() test
Browse files Browse the repository at this point in the history
Use a proper temporary file inside the object_type_from_fd() test,
instead of relying on the temporary directory being /tmp/ and hard coding
that fact.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Aug 26, 2024
1 parent 462e13e commit 598c228
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libbpf-rs/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ mod tests {
use std::io;
use std::os::fd::AsFd;

use tempfile::NamedTempFile;


#[test]
fn test_roundup() {
for i in 1..=256 {
Expand Down Expand Up @@ -212,14 +215,11 @@ mod tests {
/// loaded.
#[test]
fn test_object_type_from_fd_with_unexpected_fds() {
let path = "/tmp/libbpf-rs_not_a_bpf_object";
let not_object = fs::File::create(path).expect("failed to create a plain file");
let not_object = NamedTempFile::new().unwrap();

let _ = object_type_from_fd(not_object.as_fd())
.expect_err("a common file was treated as a BPF object");
let _ = object_type_from_fd(io::stdout().as_fd())
.expect_err("the stdout fd was treated as a BPF object");

fs::remove_file(path).expect("failed to remove temporary file");
}
}

0 comments on commit 598c228

Please sign in to comment.