From 598c2289e82c7a2bf2d249f2f217cdd8521d15ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Mon, 26 Aug 2024 10:07:09 -0700 Subject: [PATCH] Use proper temporary file in object_type_from_fd() test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- libbpf-rs/src/util.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libbpf-rs/src/util.rs b/libbpf-rs/src/util.rs index bfe3f6c2..d5b8ea19 100644 --- a/libbpf-rs/src/util.rs +++ b/libbpf-rs/src/util.rs @@ -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 { @@ -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"); } }