blob: a65fb2ef8b15d7d68c0d4f634f7e817c56d1d905 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use std::path::Path;
use std::io::BufRead;
pub struct ExampleRequest {
pub method: String,
pub path_and_query: String,
pub body: Option<String>,
}
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: 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: body,
}
}
|