do not create test files in /tmp anymore

This commit is contained in:
Fabrice Reix 2021-01-14 08:09:04 +01:00
parent d8b01b928e
commit 836ad872a7
4 changed files with 5 additions and 27 deletions

View File

@ -89,25 +89,8 @@ mod tests {
use super::*; use super::*;
#[cfg(test)]
pub fn create_test_file() {
let path = Path::new("/tmp/data.bin");
let display = path.display();
if File::open(path).is_err() {
match File::create(&path) {
Err(why) => panic!("couldn't create {}: {:?}", display, why),
Ok(mut file) => match file.write_all(b"Hello World!") {
Err(why) => panic!("couldn't write to {}: {:?}", display, why),
Ok(_) => println!("successfully wrote to {}", display),
},
}
}
}
#[test] #[test]
pub fn test_body_file() { pub fn test_body_file() {
create_test_file();
// file, data.bin; // file, data.bin;
let whitespace = Whitespace { let whitespace = Whitespace {
value: String::from(" "), value: String::from(" "),
@ -117,7 +100,7 @@ mod tests {
let bytes = Bytes::File { let bytes = Bytes::File {
space0: whitespace.clone(), space0: whitespace.clone(),
filename: Filename { filename: Filename {
value: String::from("/tmp/data.bin"), value: String::from("tests/data.bin"),
source_info: SourceInfo::init(1, 7, 1, 15), source_info: SourceInfo::init(1, 7, 1, 15),
}, },
space1: whitespace.clone(), space1: whitespace.clone(),
@ -125,7 +108,7 @@ mod tests {
let variables = HashMap::new(); let variables = HashMap::new();
assert_eq!( assert_eq!(
eval_bytes(bytes, &variables, "current_dir".to_string()).unwrap(), eval_bytes(bytes, &variables, ".".to_string()).unwrap(),
b"Hello World!" b"Hello World!"
); );
} }

View File

@ -0,0 +1 @@
localhost FALSE / FALSE 0 cookie2 valueA

View File

@ -0,0 +1 @@
Hello World!

View File

@ -1,5 +1,3 @@
use std::fs::File;
use std::io::prelude::*;
use std::time::Duration; use std::time::Duration;
use hurl::http::*; use hurl::http::*;
@ -701,15 +699,10 @@ fn test_cookie_storage() {
#[test] #[test]
fn test_cookie_file() { fn test_cookie_file() {
let temp_file = "/tmp/cookies";
let mut file = File::create(temp_file).expect("can not create temp file!");
file.write_all(b"localhost\tFALSE\t/\tFALSE\t0\tcookie2\tvalueA\n")
.unwrap();
let options = ClientOptions { let options = ClientOptions {
follow_location: false, follow_location: false,
max_redirect: None, max_redirect: None,
cookie_input_file: Some(temp_file.to_string()), cookie_input_file: Some("tests/cookies.txt".to_string()),
proxy: None, proxy: None,
no_proxy: None, no_proxy: None,
verbose: false, verbose: false,