summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs23
-rw-r--r--tests/parse_es_requests.rs24
2 files changed, 25 insertions, 22 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 811b4b9..2d06d81 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,7 +1,6 @@
-
-use hyper::{Request, Body, Method};
-use std::path::Path;
+use hyper::{Body, Method, Request};
use std::io::BufRead;
+use std::path::Path;
pub struct ExampleParts {
pub method: String,
@@ -10,11 +9,19 @@ pub struct ExampleParts {
}
pub fn load_parts(path: &Path) -> ExampleParts {
-
let file = std::fs::File::open(path).unwrap();
let mut lines = std::io::BufReader::new(file).lines();
- let first_line: Vec<String> = lines.next().unwrap().unwrap().split(" ").map(|v| v.into()).collect();
- let body: Vec<String> = lines.map(|v| v.into()).collect::<Result<Vec<String>, _>>().unwrap();
+ let first_line: Vec<String> = lines
+ .next()
+ .unwrap()
+ .unwrap()
+ .split(" ")
+ .map(|v| v.into())
+ .collect();
+ let body: Vec<String> = lines
+ .map(|v| v.into())
+ .collect::<Result<Vec<String>, _>>()
+ .unwrap();
let body: Option<String> = if body.len() <= 1 {
None
} else {
@@ -32,7 +39,9 @@ pub fn load_request(path: &Path) -> Request<Body> {
let parts = load_parts(path);
Request::builder()
.uri(parts.path_and_query)
- .method(Method::from_bytes(parts.method.as_bytes()).expect("valid method in example text file"))
+ .method(
+ Method::from_bytes(parts.method.as_bytes()).expect("valid method in example text file"),
+ )
.body(match parts.body {
Some(data) => Body::from(data),
None => Body::empty(),
diff --git a/tests/parse_es_requests.rs b/tests/parse_es_requests.rs
index a55e461..c8081c7 100644
--- a/tests/parse_es_requests.rs
+++ b/tests/parse_es_requests.rs
@@ -1,8 +1,7 @@
-
-use std::fs;
-use std::ffi::OsStr;
use es_public_proxy::parse::{ScrollBody, SearchBody};
-use es_public_proxy::{ProxyConfig, filter_request};
+use es_public_proxy::{filter_request, ProxyConfig};
+use std::ffi::OsStr;
+use std::fs;
mod common;
@@ -15,13 +14,12 @@ fn basic_load() {
#[test]
fn parse_search_bodies() {
-
let file_paths = fs::read_dir("tests/files/search").unwrap();
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
let parts = common::load_parts(&path);
if let Some(body) = parts.body {
@@ -36,13 +34,12 @@ fn parse_search_bodies() {
#[test]
fn parse_scroll_bodies() {
-
let file_paths = fs::read_dir("tests/files/scroll").unwrap();
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
let parts = common::load_parts(&path);
if let Some(body) = parts.body {
@@ -55,7 +52,6 @@ fn parse_scroll_bodies() {
#[test]
fn filter_search_requests() {
-
let file_paths = fs::read_dir("tests/files/search").unwrap();
let mut config = ProxyConfig::default();
config.allow_all_indices = Some(true);
@@ -64,7 +60,7 @@ fn filter_search_requests() {
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
println!(" filtering: {}", path.display());
let req = common::load_request(&path);
@@ -74,7 +70,6 @@ fn filter_search_requests() {
#[test]
fn filter_scroll_requests() {
-
let file_paths = fs::read_dir("tests/files/scroll").unwrap();
let mut config = ProxyConfig::default();
config.allow_all_indices = Some(true);
@@ -83,7 +78,7 @@ fn filter_scroll_requests() {
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
println!(" filtering: {}", path.display());
let req = common::load_request(&path);
@@ -93,7 +88,6 @@ fn filter_scroll_requests() {
#[test]
fn filter_failures() {
-
let file_paths = fs::read_dir("tests/files/search_fail").unwrap();
let mut config = ProxyConfig::default();
config.allow_all_indices = Some(true);
@@ -102,7 +96,7 @@ fn filter_failures() {
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
println!(" filtering: {}", path.display());
let req = common::load_request(&path);
@@ -115,7 +109,7 @@ fn filter_failures() {
for path in file_paths {
let path = path.unwrap().path();
if path.extension() != Some(OsStr::new("txt")) {
- continue
+ continue;
}
println!(" filtering: {}", path.display());
let req = common::load_request(&path);