diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auth.rs | 11 | ||||
-rw-r--r-- | tests/navigation.rs | 12 | ||||
-rw-r--r-- | tests/serve_request.rs | 6 | ||||
-rw-r--r-- | tests/upload_files.rs | 23 |
4 files changed, 28 insertions, 24 deletions
diff --git a/tests/auth.rs b/tests/auth.rs index 7074d00..4cabb77 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -5,6 +5,7 @@ use assert_fs::fixture::TempDir; use fixtures::{port, tmpdir, Error, FILES}; use pretty_assertions::assert_eq; use reqwest::StatusCode; +use reqwest::blocking::Client; use rstest::rstest; use select::document::Document; use select::predicate::Text; @@ -44,7 +45,7 @@ fn auth_accepts( sleep(Duration::from_secs(1)); - let client = reqwest::Client::new(); + let client = Client::new(); let response = client .get(format!("http://localhost:{}", port).as_str()) .basic_auth(client_username, Some(client_password)) @@ -108,7 +109,7 @@ fn auth_rejects( sleep(Duration::from_secs(1)); - let client = reqwest::Client::new(); + let client = Client::new(); let status = client .get(format!("http://localhost:{}", port).as_str()) .basic_auth(client_username, Some(client_password)) @@ -166,7 +167,7 @@ fn auth_multiple_accounts_pass( sleep(Duration::from_secs(1)); - let client = reqwest::Client::new(); + let client = Client::new(); let response = client .get(format!("http://localhost:{}", port).as_str()) @@ -201,7 +202,7 @@ fn auth_multiple_accounts_wrong_username(tmpdir: TempDir, port: u16) -> Result<( sleep(Duration::from_secs(1)); - let client = reqwest::Client::new(); + let client = Client::new(); let status = client .get(format!("http://localhost:{}", port).as_str()) @@ -244,7 +245,7 @@ fn auth_multiple_accounts_wrong_password( sleep(Duration::from_secs(1)); - let client = reqwest::Client::new(); + let client = Client::new(); let status = client .get(format!("http://localhost:{}", port).as_str()) diff --git a/tests/navigation.rs b/tests/navigation.rs index 94e7355..224f100 100644 --- a/tests/navigation.rs +++ b/tests/navigation.rs @@ -27,7 +27,7 @@ fn index_gets_trailing_slash(tmpdir: TempDir, port: u16) -> Result<(), Error> { let base_url = Url::parse(&format!("http://localhost:{}", port))?; let expected_url = format!("{}", base_url); - let resp = reqwest::get(base_url.as_str())?; + let resp = reqwest::blocking::get(base_url.as_str())?; assert_eq!(resp.url().as_str(), expected_url); child.kill()?; @@ -48,15 +48,15 @@ fn can_navigate_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<(), Err sleep(Duration::from_secs(1)); let base_url = Url::parse(&format!("http://localhost:{}/", port))?; - let initial_body = reqwest::get(base_url.as_str())?.error_for_status()?; + let initial_body = reqwest::blocking::get(base_url.as_str())?.error_for_status()?; let initial_parsed = Document::from_read(initial_body)?; for &directory in DIRECTORIES { let dir_elem = get_link_from_text(&initial_parsed, &directory).expect("Dir not found."); - let body = reqwest::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?; + let body = reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?; let parsed = Document::from_read(body)?; let back_link = get_link_from_text(&parsed, "Parent directory").expect("Back link not found."); - let resp = reqwest::get(&format!("{}{}", base_url, back_link))?; + let resp = reqwest::blocking::get(&format!("{}{}", base_url, back_link))?; // Now check that we can actually get back to the original location we came from using the // link. @@ -96,7 +96,7 @@ fn can_navigate_deep_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<() // In the end, we'll have to end up where we came from. let mut next_url = base_url.clone(); for dir_name in dir_names.iter() { - let resp = reqwest::get(next_url.as_str())?; + let resp = reqwest::blocking::get(next_url.as_str())?; let body = resp.error_for_status()?; let parsed = Document::from_read(body)?; let dir_elem = get_link_from_text(&parsed, &dir_name).expect("Dir not found."); @@ -106,7 +106,7 @@ fn can_navigate_deep_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<() // Now try to get out the tree again using links only. while next_url != base_url { - let resp = reqwest::get(next_url.as_str())?; + let resp = reqwest::blocking::get(next_url.as_str())?; let body = resp.error_for_status()?; let parsed = Document::from_read(body)?; let dir_elem = diff --git a/tests/serve_request.rs b/tests/serve_request.rs index 064e196..9c30bb8 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -19,7 +19,7 @@ fn serves_requests_with_no_options(tmpdir: TempDir) -> Result<(), Error> { sleep(Duration::from_secs(1)); - let body = reqwest::get("http://localhost:8080")?.error_for_status()?; + let body = reqwest::blocking::get("http://localhost:8080")?.error_for_status()?; let parsed = Document::from_read(body)?; for &file in FILES { assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); @@ -41,7 +41,7 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( sleep(Duration::from_secs(1)); - let body = reqwest::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; let parsed = Document::from_read(body)?; for &file in FILES { assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); @@ -51,7 +51,7 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( .find(|x: &Node| x.text() == directory) .next() .is_some()); - let dir_body = reqwest::get(format!("http://localhost:{}/{}", port, directory).as_str())? + let dir_body = reqwest::blocking::get(format!("http://localhost:{}/{}", port, directory).as_str())? .error_for_status()?; let dir_body_parsed = Document::from_read(dir_body)?; for &file in FILES { diff --git a/tests/upload_files.rs b/tests/upload_files.rs index 53833a6..58707c5 100644 --- a/tests/upload_files.rs +++ b/tests/upload_files.rs @@ -3,7 +3,7 @@ mod fixtures; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; use fixtures::{port, tmpdir, Error}; -use reqwest::multipart; +use reqwest::blocking::{multipart, Client}; use rstest::rstest; use select::document::Document; use select::predicate::{Attr, Text}; @@ -26,7 +26,8 @@ fn uploading_files_works(tmpdir: TempDir, port: u16) -> Result<(), Error> { sleep(Duration::from_secs(1)); // Before uploading, check whether the uploaded file does not yet exist. - let body = reqwest::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())? + .error_for_status()?; let parsed = Document::from_read(body)?; assert!(parsed.find(Text).all(|x| x.text() != test_file_name)); @@ -43,7 +44,7 @@ fn uploading_files_works(tmpdir: TempDir, port: u16) -> Result<(), Error> { .mime_str("text/plain")?; let form = form.part("file_to_upload", part); - let client = reqwest::Client::new(); + let client = Client::new(); client .post(format!("http://localhost:{}{}", port, upload_action).as_str()) .multipart(form) @@ -51,7 +52,7 @@ fn uploading_files_works(tmpdir: TempDir, port: u16) -> Result<(), Error> { .error_for_status()?; // After uploading, check whether the uploaded file is now getting listed. - let body = reqwest::get(format!("http://localhost:{}", port).as_str())?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?; let parsed = Document::from_read(body)?; assert!(parsed.find(Text).any(|x| x.text() == test_file_name)); @@ -74,13 +75,14 @@ fn uploading_files_is_prevented(tmpdir: TempDir, port: u16) -> Result<(), Error> sleep(Duration::from_secs(1)); // Before uploading, check whether the uploaded file does not yet exist. - let body = reqwest::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())? + .error_for_status()?; let parsed = Document::from_read(body)?; assert!(parsed.find(Text).all(|x| x.text() != test_file_name)); - + // Ensure the file upload form is not present assert!(parsed.find(Attr("id", "file_submit")).next().is_none()); - + // Then try to upload anyway let form = multipart::Form::new(); let part = multipart::Part::text("this should not be uploaded") @@ -88,16 +90,17 @@ fn uploading_files_is_prevented(tmpdir: TempDir, port: u16) -> Result<(), Error> .mime_str("text/plain")?; let form = form.part("file_to_upload", part); - let client = reqwest::Client::new(); + let client = Client::new(); // Ensure uploading fails and returns an error assert!(client .post(format!("http://localhost:{}{}", port, "/upload?path=/").as_str()) .multipart(form) .send()? - .error_for_status().is_err()); + .error_for_status() + .is_err()); // After uploading, check whether the uploaded file is now getting listed. - let body = reqwest::get(format!("http://localhost:{}", port).as_str())?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?; let parsed = Document::from_read(body)?; assert!(!parsed.find(Text).any(|x| x.text() == test_file_name)); |