Skip to content

Commit

Permalink
test: added tests for datastore query of events that cover the querie…
Browse files Browse the repository at this point in the history
…d range
  • Loading branch information
ErikBjare committed May 15, 2021
1 parent e027018 commit 602ddb2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aw-datastore/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ impl DatastoreInstance {
"
SELECT count(*) FROM events
WHERE bucketrow = ?1
AND (starttime >= ?2 OR endtime <= ?3)",
AND endtime >= ?2
AND starttime <= ?3",
) {
Ok(stmt) => stmt,
Err(err) => {
Expand Down
37 changes: 37 additions & 0 deletions aw-datastore/tests/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,43 @@ mod datastore_tests {
assert_eq!(event_count, 2);
}

/// Tests that events that cover a timeperiod get included when that timeperiod is queried.
#[test]
fn test_get_events_filters_cover() {
// TODO: Also test event-cutoff, although perhaps that happens in the transforms/queries?

// Setup datastore
let ds = Datastore::new_in_memory(false);
let bucket = create_test_bucket(&ds);

let now = Utc::now();

// Insert event
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(100),
data: json_map! {"key": json!("value")},
};

let event_list = [e1.clone()];
ds.insert_events(&bucket.id, &event_list).unwrap();

info!("Get event that covers queried timeperiod");
let query_start = now + Duration::seconds(1);
let query_end = query_start + Duration::seconds(1);
let fetched_events_limit = ds
.get_events(&bucket.id, Some(query_start), Some(query_end), Some(1))
.unwrap();
assert_eq!(fetched_events_limit.len(), 1);

// Get eventcount
let event_count = ds
.get_event_count(&bucket.id, Some(query_start), Some(query_end))
.unwrap();
assert_eq!(event_count, 1);
}

#[test]
fn test_events_delete() {
// Setup datastore
Expand Down

0 comments on commit 602ddb2

Please sign in to comment.