From 38d3f8143a26c448f9f4898962ceca3d3e877163 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 18 Aug 2020 00:06:02 -0700 Subject: start of test infra --- tests/common/mod.rs | 24 ++++++++++++++++++++++++ tests/files/GET_search.txt | 10 ++++++++++ tests/files/GET_search_multi_match.txt | 9 +++++++++ tests/parse_es_requests.rs | 16 ++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 tests/common/mod.rs create mode 100644 tests/files/GET_search.txt create mode 100644 tests/files/GET_search_multi_match.txt create mode 100644 tests/parse_es_requests.rs (limited to 'tests') diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 0000000..f0b9bea --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,24 @@ + +use std::io::BufRead; + +pub struct ExampleRequest { + pub method: String, + pub path_and_query: String, + pub body: Option, +} + +pub fn load_request(name: &str) -> ExampleRequest { + + let path = format!("tests/files/{}.txt", name); + let file = std::fs::File::open(path).unwrap(); + let mut lines = std::io::BufReader::new(file).lines(); + let first_line: Vec = lines.next().unwrap().unwrap().split(" ").map(|v| v.into()).collect(); + let body: Vec = lines.map(|v| v.into()).collect::, _>>().unwrap(); + let body: String = body.join("\n"); + + ExampleRequest { + method: first_line[0].clone(), + path_and_query: first_line[1].clone(), + body: Some(body), + } +} diff --git a/tests/files/GET_search.txt b/tests/files/GET_search.txt new file mode 100644 index 0000000..1ed6157 --- /dev/null +++ b/tests/files/GET_search.txt @@ -0,0 +1,10 @@ +GET /_search +{ + "query": { + "match": { + "message": { + "query": "this is a test" + } + } + } +} diff --git a/tests/files/GET_search_multi_match.txt b/tests/files/GET_search_multi_match.txt new file mode 100644 index 0000000..17aca77 --- /dev/null +++ b/tests/files/GET_search_multi_match.txt @@ -0,0 +1,9 @@ +GET /_search +{ + "query": { + "multi_match" : { + "query" : "this is a test", + "fields" : [ "subject^3", "message" ] + } + } +} diff --git a/tests/parse_es_requests.rs b/tests/parse_es_requests.rs new file mode 100644 index 0000000..e918da9 --- /dev/null +++ b/tests/parse_es_requests.rs @@ -0,0 +1,16 @@ + +mod common; + +#[test] +fn basic_load() { + let request = common::load_request("GET_search"); + assert_eq!(request.method, "GET"); + assert_eq!(request.path_and_query, "/_search"); +} + +#[test] +fn basic_parse() { + let request = common::load_request("GET_search"); + assert_eq!(request.method, "GET"); + assert_eq!(request.path_and_query, "/_search"); +} -- cgit v1.2.3