From bb552c9d0060cf49e187d1b06460a838ef19828d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 22 Aug 2020 15:41:49 -0700 Subject: start on test framework and query JSON parser --- src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ tests/files/GET_uri_search.txt | 1 + tests/parse_es_requests.rs | 4 ++++ 3 files changed, 40 insertions(+) create mode 100644 src/lib.rs create mode 100644 tests/files/GET_uri_search.txt diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1ba6207 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,35 @@ + +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiRequest { + pub method: String, + pub path_and_query: String, + pub body: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiBody { + pub query: Option, + pub from: Option, + pub size: Option, + pub sort: Option, // XXX + pub slice: Option, // XXX +} + +#[derive(Serialize, Deserialize, Debug)] +pub enum ApiQuery { + #[serde(rename = "match")] + Match(MatchQuery), +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct MatchQuery { + message: QueryField, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct QueryField{ + query: String, + fuzziness: Option, +} diff --git a/tests/files/GET_uri_search.txt b/tests/files/GET_uri_search.txt new file mode 100644 index 0000000..e5e0567 --- /dev/null +++ b/tests/files/GET_uri_search.txt @@ -0,0 +1 @@ +GET /my-index-000001/_search?q=user.id:kimchy diff --git a/tests/parse_es_requests.rs b/tests/parse_es_requests.rs index e918da9..01ea64a 100644 --- a/tests/parse_es_requests.rs +++ b/tests/parse_es_requests.rs @@ -1,4 +1,6 @@ +use es_public_proxy::ApiBody; + mod common; #[test] @@ -13,4 +15,6 @@ fn basic_parse() { let request = common::load_request("GET_search"); assert_eq!(request.method, "GET"); assert_eq!(request.path_and_query, "/_search"); + + let thing: ApiBody = serde_json::from_str(&request.body.unwrap()).unwrap(); } -- cgit v1.2.3