summaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-08-24 13:43:00 -0700
committerBryan Newbold <bnewbold@archive.org>2020-08-24 13:43:00 -0700
commit03bb85c57086e4371d827b5fbd496d3e820496b7 (patch)
tree0b6b74336b6dffe314e952ffb19aea45216b5815 /tests/common
parent95fca87e9f5fae3283ade00363bfd2d094dd0689 (diff)
downloades-public-proxy-03bb85c57086e4371d827b5fbd496d3e820496b7.tar.gz
es-public-proxy-03bb85c57086e4371d827b5fbd496d3e820496b7.zip
tests: try all query files; some small refactors
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/mod.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index f0b9bea..a65fb2e 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,4 +1,5 @@
+use std::path::Path;
use std::io::BufRead;
pub struct ExampleRequest {
@@ -7,18 +8,27 @@ pub struct ExampleRequest {
pub body: Option<String>,
}
-pub fn load_request(name: &str) -> ExampleRequest {
-
+pub fn load_request_by_name(name: &str) -> ExampleRequest {
let path = format!("tests/files/{}.txt", name);
+ let path = Path::new(&path);
+ load_request(&path)
+}
+
+pub fn load_request(path: &Path) -> ExampleRequest {
+
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 body: String = body.join("\n");
+ let body: Option<String> = if body.len() <= 1 {
+ None
+ } else {
+ Some(body.join("\n"))
+ };
ExampleRequest {
method: first_line[0].clone(),
path_and_query: first_line[1].clone(),
- body: Some(body),
+ body: body,
}
}