Skip to content

Commit

Permalink
chore(es): add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
etolbakov authored Jul 12, 2024
1 parent 6887b47 commit 1f13d9d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,40 @@ fn parse_and_convert(literal: JsonLiteral, parser: &StrptimeParser) -> anyhow::R
Ok(literal)
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use quickwit_datetime::StrptimeParser;

use crate::elastic_query_dsl::range_query::parse_and_convert;
use crate::JsonLiteral;

#[test]
fn test_parse_and_convert() {
let parser = StrptimeParser::from_str("%Y-%m-%d %H:%M:%S").unwrap();

// valid datetime
let input = JsonLiteral::String("2022-12-30 05:45:00".to_string());
let result = parse_and_convert(input, &parser)?;
assert_eq!(
result,
JsonLiteral::String("2022-12-30 5:45:00.0 +00:00:00".to_string())
);

// invalid datetime
let input = JsonLiteral::String("invalid datetime".to_string());
let result = parse_and_convert(input, &parser);
assert!(result.is_err());
assert!(result
.unwrap_err()
.to_string()
.contains("Failed to parse date time"));

// non_string(number) input
let input = JsonLiteral::Number(27.into());
let result = parse_and_convert(input.clone(), &parser)?;
assert_eq!(result, input);
}
}

0 comments on commit 1f13d9d

Please sign in to comment.