summaryrefslogtreecommitdiffstats
path: root/tests/parse_es_requests.rs
blob: 57be06aa2dad0877853fe0aadf8b534e2c71abca (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
35
36
37
38
39
40
41

use std::fs;
use std::ffi::OsStr;
use es_public_proxy::SearchBody;

mod common;

#[test]
fn basic_load() {
    let request = common::load_request_by_name("GET_search");
    assert_eq!(request.method, "GET");
    assert_eq!(request.path_and_query, "/_search");
}

#[test]
fn basic_parse() {
    let request = common::load_request_by_name("GET_search");
    assert_eq!(request.method, "GET");
    assert_eq!(request.path_and_query, "/_search");

    let _parsed: SearchBody = serde_json::from_str(&request.body.unwrap()).unwrap();
}

#[test]
fn parse_all_requests() {

    let file_paths = fs::read_dir("tests/files").unwrap();

    for path in file_paths {
        let path = path.unwrap().path();
        if path.extension() != Some(OsStr::new("txt")) {
            continue
        }
        let request = common::load_request(&path);
        if let Some(body) = request.body {
            println!("parsing: {}", path.display());
            println!("BODY: {}", body);
            let _parsed: SearchBody = serde_json::from_str(&body).unwrap();
        }
    }
}