From c080df3c965fcd23c4f936c256c075ce8deeea85 Mon Sep 17 00:00:00 2001 From: Esteban Blanc Date: Mon, 1 May 2023 18:25:58 +0200 Subject: [PATCH] tests: Fix server returned content Signed-off-by: Esteban Blanc --- tests/auth.rs | 2 +- tests/charset_html_found.rs | 6 ++++-- tests/charset_http_found.rs | 6 ++++-- tests/external.rs | 6 +----- tests/filters.rs | 14 +++++--------- tests/fixtures/mod.rs | 6 +++++- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index e2215e8..b74809e 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -7,7 +7,7 @@ use std::process::Command; use std::process::Stdio; use std::sync::Once; -const PAGE: &'static str = "tests/fixtures/index.html"; +const PAGE: &'static str = "tests/fixtures/"; const IP: &'static str = "0.0.0.0"; static START: Once = Once::new(); diff --git a/tests/charset_html_found.rs b/tests/charset_html_found.rs index 6d6f1f3..e40b208 100644 --- a/tests/charset_html_found.rs +++ b/tests/charset_html_found.rs @@ -6,6 +6,7 @@ use std::fs; use std::process::{Command, Stdio}; use std::sync::Once; +const PAGE: &'static str = "tests/fixtures"; const PAGE_META: &'static str = "tests/fixtures/charset_test_html.html"; const IP: &'static str = "0.0.0.0"; static START: Once = Once::new(); @@ -14,13 +15,14 @@ static START: Once = Once::new(); fn test_html_charset_found() { // Spawn a single instance of a local http server usable by all tests in this module. START.call_once(|| { - fixtures::spawn_local_http_server(PAGE_META, false, None); + fixtures::spawn_local_http_server(PAGE, false, None); }); let output_dir = "charset_html_found"; let file_dir = format!("{}/{}", output_dir, IP); + let url = format!("{}/charset_test_html.html", fixtures::HTTP_ADDR); let mut cmd = Command::new(env!("CARGO_BIN_EXE_suckit")) - .args(&[fixtures::HTTP_ADDR, "-o", output_dir]) + .args(&[&url, "-o", output_dir]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .spawn() diff --git a/tests/charset_http_found.rs b/tests/charset_http_found.rs index f61ab57..f5f6ce8 100644 --- a/tests/charset_http_found.rs +++ b/tests/charset_http_found.rs @@ -8,6 +8,7 @@ use std::sync::Once; use lazy_static::lazy_static; +const PAGE: &'static str = "tests/fixtures/"; const PAGE_NO_META: &'static str = "tests/fixtures/charset_test_html_no_meta.html"; const IP: &'static str = "0.0.0.0"; static START: Once = Once::new(); @@ -21,13 +22,14 @@ lazy_static! { fn test_http_charset_found() { // Spawn a single instance of a local http server usable by all tests in this module. START.call_once(|| { - fixtures::spawn_local_http_server(PAGE_NO_META, false, Some(&CHARSET_HEADER)); + fixtures::spawn_local_http_server(PAGE, false, Some(&CHARSET_HEADER)); }); let output_dir = "charset_html_found"; let file_dir = format!("{}/{}", output_dir, IP); + let url = format!("{}/charset_test_html_no_meta.html", fixtures::HTTP_ADDR); let mut cmd = Command::new(env!("CARGO_BIN_EXE_suckit")) - .args(&[fixtures::HTTP_ADDR, "-o", output_dir]) + .args(&[&url, "-o", output_dir]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .spawn() diff --git a/tests/external.rs b/tests/external.rs index 550ed02..889362d 100644 --- a/tests/external.rs +++ b/tests/external.rs @@ -8,7 +8,7 @@ use std::process::Command; use std::process::Stdio; use std::sync::Once; -const PAGE: &'static str = "tests/fixtures/index.html"; +const PAGE: &'static str = "tests/fixtures/"; const IP: &'static str = "0.0.0.0"; static START: Once = Once::new(); @@ -38,8 +38,6 @@ fn with_external() { "0", "--ext-depth", "1", - "-j", - "16", ]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -68,8 +66,6 @@ fn without_external() { "0", "--ext-depth", "0", - "-j", - "16", ]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) diff --git a/tests/filters.rs b/tests/filters.rs index 63b3902..0bb5cda 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -8,7 +8,7 @@ use std::process::Command; use std::process::Stdio; use std::sync::Once; -const PAGE: &'static str = "tests/fixtures/index.html"; +const PAGE: &'static str = "tests/fixtures/"; const IP: &'static str = "0.0.0.0"; static START: Once = Once::new(); @@ -119,10 +119,8 @@ fn visit_exclude_filter() { let status = cmd.wait().unwrap(); assert!(status.success()); let paths = read_dir(&files_dir).unwrap(); - let mp3_count = get_file_count_with_pattern(".mp3", &files_dir).unwrap(); - let txt_count = get_file_count_with_pattern(".txt", &files_dir).unwrap(); - let index_file = 1; - assert_eq!(paths.count(), mp3_count + txt_count + index_file); + let jpeg_count = get_file_count_with_pattern(".jpe?g", &files_dir).unwrap(); + assert_eq!(jpeg_count, 0); std::fs::remove_dir_all(output_dir).unwrap(); } @@ -214,10 +212,8 @@ fn download_exclude_filter() { let status = cmd.wait().unwrap(); assert!(status.success()); let paths = read_dir(&files_dir).unwrap(); - let mp3_count = get_file_count_with_pattern(".mp3", &files_dir).unwrap(); - let txt_count = get_file_count_with_pattern(".txt", &files_dir).unwrap(); - let index_file = 1; - assert_eq!(paths.count(), mp3_count + txt_count + index_file); + let jpeg_count = get_file_count_with_pattern(".jpe?g", &files_dir).unwrap(); + assert_eq!(jpeg_count, 0); std::fs::remove_dir_all(output_dir).unwrap(); } diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index cdc0dba..f85dc6e 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -31,7 +31,11 @@ pub fn spawn_local_http_server( response.add_header(h); response.boxed() } else { - Response::from_file(File::open(page).unwrap()).boxed() + let file = match request.url() { + "/" => format!("{}{}", page, "index.html"), + other => format!("{}{}", page, other), + }; + Response::from_file(File::open(file).unwrap()).boxed() }; match headers {