Skip to content

Commit

Permalink
cql_types_test: Don't rely on MIN/MAX values of NaiveDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorak-mmk committed Jan 24, 2024
1 parent 2af0214 commit 0270368
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions scylla/src/transport/cql_types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,14 @@ async fn test_counter() {
#[cfg(feature = "chrono")]
#[tokio::test]
async fn test_naive_date() {
use chrono::Datelike;
use chrono::NaiveDate;

let session: Session = init_test("chrono_naive_date_tests", "date").await;

let min_naive_date: NaiveDate = NaiveDate::MIN;
assert_eq!(
min_naive_date,
NaiveDate::from_ymd_opt(-262144, 1, 1).unwrap()
);

let max_naive_date: NaiveDate = NaiveDate::MAX;
assert_eq!(
max_naive_date,
NaiveDate::from_ymd_opt(262143, 12, 31).unwrap()
);
let min_naive_date_string = min_naive_date.format("%Y-%m-%d").to_string();
let min_naive_date_out_of_range_string = (min_naive_date.year() - 1).to_string() + "-12-31";

let tests = [
// Basic test values
Expand All @@ -235,12 +228,12 @@ async fn test_naive_date() {
Some(NaiveDate::from_ymd_opt(-1, 12, 31).unwrap()),
),
// min/max values allowed by NaiveDate
("-262144-01-01", Some(min_naive_date)),
(min_naive_date_string.as_str(), Some(min_naive_date)),
// NOTICE: dropped for Cassandra 4 compatibility
//("262143-12-31", Some(max_naive_date)),

// 1 less/more than min/max values allowed by NaiveDate
("-262145-12-31", None),
// Slightly less/more than min/max values allowed by NaiveDate
(min_naive_date_out_of_range_string.as_str(), None),
// NOTICE: dropped for Cassandra 4 compatibility
//("262144-01-01", None),
// min/max values allowed by the database
Expand Down

0 comments on commit 0270368

Please sign in to comment.