Skip to content

Commit cc46520

Browse files
committed
Add tests for deletion
1 parent 1b91a1c commit cc46520

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/fields_tests/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Context;
22
use chrono::{DateTime, Utc};
33

44
#[pco_store::store(timestamp = collected_at, group_by = [database_id, granularity])]
5-
#[derive(Debug, PartialEq)]
5+
#[derive(Clone, Debug, PartialEq)]
66
pub struct QueryStat {
77
pub database_id: i64,
88
pub granularity: i32,
@@ -46,7 +46,7 @@ async fn test() -> anyhow::Result<()> {
4646
let mut stats = Vec::new();
4747
stats.push(QueryStat { fingerprint: 1, ..s });
4848
stats.push(QueryStat { fingerprint: 2, ..s });
49-
CompressedQueryStats::store(db, stats).await?;
49+
CompressedQueryStats::store(db, stats.clone()).await?;
5050

5151
// Including all fields
5252
let full = vec![QueryStat { fingerprint: 1, ..s }, QueryStat { fingerprint: 2, ..s }];
@@ -69,6 +69,11 @@ async fn test() -> anyhow::Result<()> {
6969
f.fingerprint = vec![2];
7070
assert_eq!(vec![QueryStat { fingerprint: 2, ..s }], load(db, f.clone(), &[]).await?);
7171

72+
// Fields can be skipped skipped when deleting rows
73+
assert_eq!(partial, delete(db, filter.clone(), &[]).await?);
74+
CompressedQueryStats::store(db, stats).await?;
75+
assert_eq!(full, delete(db, filter.clone(), ()).await?);
76+
7277
Ok(())
7378
}
7479

@@ -80,3 +85,12 @@ async fn load(db: &deadpool_postgres::Client, filter: Filter, fields: impl TryIn
8085
rows.sort_by_key(|s| (s.fingerprint, s.collected_at));
8186
Ok(rows)
8287
}
88+
89+
async fn delete(db: &deadpool_postgres::Client, filter: Filter, fields: impl TryInto<Fields>) -> anyhow::Result<Vec<QueryStat>> {
90+
let mut rows = Vec::new();
91+
for group in CompressedQueryStats::delete(db, filter, fields).await? {
92+
rows.extend(group.decompress()?);
93+
}
94+
rows.sort_by_key(|s| (s.fingerprint, s.collected_at));
95+
Ok(rows)
96+
}

0 commit comments

Comments
 (0)