Skip to content

Commit d12dc1a

Browse files
committed
Refactor test_multipart_form_with_file: Use a cross-platform temporary directory for test file creation and improve path handling.
1 parent bb5cd7c commit d12dc1a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tests/integration/multipart.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ fn test_multipart_form_with_request() {
150150

151151
#[test]
152152
fn test_multipart_form_with_file() {
153-
// Create a test file
154-
let test_file_path = "/tmp/test_multipart_file.txt";
155-
std::fs::write(test_file_path, b"This is test file content").unwrap();
153+
// Create a test file in a cross-platform temporary directory
154+
let temp_dir = std::env::temp_dir();
155+
let test_file_path = temp_dir.join("test_multipart_file.txt");
156+
let test_file_path_str = test_file_path.to_str().unwrap();
157+
std::fs::write(&test_file_path, b"This is test file content").unwrap();
156158

157159
// Build a client
158160
let client_builder_ptr = client_builder_create();
@@ -181,11 +183,11 @@ fn test_multipart_form_with_file() {
181183

182184
// Add the file
183185
let file_field = CString::new("file").unwrap();
184-
let file_path = CString::new(test_file_path).unwrap();
186+
let file_path_cstr = CString::new(test_file_path_str).unwrap();
185187
assert!(multipart_form_add_file(
186188
form_ptr,
187189
file_field.as_ptr(),
188-
file_path.as_ptr()
190+
file_path_cstr.as_ptr()
189191
));
190192

191193
// Attach the multipart form to the request builder
@@ -214,7 +216,7 @@ fn test_multipart_form_with_file() {
214216
request_builder_destroy(builder_ptr);
215217
client_builder_destroy(client_builder_ptr);
216218
client_destroy(client_id);
217-
std::fs::remove_file(test_file_path).ok();
219+
std::fs::remove_file(&test_file_path).ok();
218220
}
219221

220222
#[test]

0 commit comments

Comments
 (0)