Skip to content

Commit 95ce76e

Browse files
committed
fix(test): correct aggregate tests to use encrypted column
The aggregate tests (count, max, min) were incorrectly testing the plain `id` column instead of the encrypted `e` column: - count_aggregate_on_encrypted_column: COUNT(*) → COUNT(e) - max_aggregate_on_encrypted_column: MAX(id) → eql_v2.max(e) - min_aggregate_on_encrypted_column: MIN(id) → eql_v2.min(e) These tests now properly verify that aggregate functions work on encrypted data, not just plain integers.
1 parent bd68344 commit 95ce76e

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

tests/sqlx/tests/aggregate_tests.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,61 @@ use sqlx::PgPool;
77

88
#[sqlx::test]
99
async fn count_aggregate_on_encrypted_column(pool: PgPool) -> Result<()> {
10-
// Test: COUNT works with encrypted columns
10+
// Test: COUNT works on encrypted columns (counts non-NULL encrypted values)
1111

12-
let count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM ore")
12+
let count: i64 = sqlx::query_scalar("SELECT COUNT(e) FROM ore")
1313
.fetch_one(&pool)
1414
.await?;
1515

16-
assert_eq!(count, 99, "should count all ORE records");
16+
assert_eq!(count, 99, "should count all non-NULL encrypted values");
1717

1818
Ok(())
1919
}
2020

2121
#[sqlx::test]
2222
async fn max_aggregate_on_encrypted_column(pool: PgPool) -> Result<()> {
23-
// Test: MAX returns highest value with ORE
23+
// Test: eql_v2.max() returns highest encrypted value
24+
// The ore table has id and e columns where e is the encrypted version of id
25+
// So eql_v2.max(e) should return the encrypted value corresponding to id=99
2426

25-
let max_id: i64 = sqlx::query_scalar("SELECT MAX(id) FROM ore WHERE id <= 50")
27+
// Get the expected max value (encrypted value where id = 99)
28+
let expected: String = sqlx::query_scalar("SELECT e::text FROM ore WHERE id = 99")
2629
.fetch_one(&pool)
2730
.await?;
2831

29-
assert_eq!(max_id, 50, "MAX should return 50");
32+
// Get the actual max from eql_v2.max()
33+
let actual: String = sqlx::query_scalar("SELECT eql_v2.max(e)::text FROM ore")
34+
.fetch_one(&pool)
35+
.await?;
36+
37+
assert_eq!(
38+
actual, expected,
39+
"eql_v2.max(e) should return the encrypted value where id = 99 (maximum)"
40+
);
3041

3142
Ok(())
3243
}
3344

3445
#[sqlx::test]
3546
async fn min_aggregate_on_encrypted_column(pool: PgPool) -> Result<()> {
36-
// Test: MIN returns lowest value with ORE
47+
// Test: eql_v2.min() returns lowest encrypted value
48+
// The ore table has id and e columns where e is the encrypted version of id
49+
// So eql_v2.min(e) should return the encrypted value corresponding to id=1
3750

38-
let min_id: i64 = sqlx::query_scalar("SELECT MIN(id) FROM ore WHERE id >= 10")
51+
// Get the expected min value (encrypted value where id = 1)
52+
let expected: String = sqlx::query_scalar("SELECT e::text FROM ore WHERE id = 1")
3953
.fetch_one(&pool)
4054
.await?;
4155

42-
assert_eq!(min_id, 10, "MIN should return 10");
56+
// Get the actual min from eql_v2.min()
57+
let actual: String = sqlx::query_scalar("SELECT eql_v2.min(e)::text FROM ore")
58+
.fetch_one(&pool)
59+
.await?;
60+
61+
assert_eq!(
62+
actual, expected,
63+
"eql_v2.min(e) should return the encrypted value where id = 1 (minimum)"
64+
);
4365

4466
Ok(())
4567
}

0 commit comments

Comments
 (0)