mirror of
https://github.com/Skallwar/suckit.git
synced 2026-09-10 07:16:19 -04:00
tests: Fix server returned content
Signed-off-by: Esteban Blanc <estblcsk@gmail.com>
This commit is contained in:
parent
208c747165
commit
c080df3c96
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
6
tests/fixtures/mod.rs
vendored
6
tests/fixtures/mod.rs
vendored
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue