Skip to content

Commit 973b525

Browse files
committed
test: order by with null
1 parent 3feaea1 commit 973b525

File tree

7 files changed

+400
-30
lines changed

7 files changed

+400
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cipherstash-proxy-integration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ cipherstash-config = "0.2.3"
2929
clap = "4.5.32"
3030
fake = { version = "4", features = ["chrono", "derive"] }
3131
hex = "0.4.3"
32+
tap = "1.0.1"
3233
uuid = { version = "1.11.0", features = ["serde", "v4"] }

packages/cipherstash-proxy-integration/src/common.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ where
143143
.collect()
144144
}
145145

146+
// Returns a vector of `Option<String>` for each row in the result set.
147+
// Nulls are represented as `None`, and non-null values are converted to `Some(String)`.
148+
pub async fn simple_query_with_null(sql: &str) -> Vec<Option<String>> {
149+
let client = connect_with_tls(PROXY).await;
150+
let rows = client.simple_query(sql).await.unwrap();
151+
rows.iter()
152+
.filter_map(|row| {
153+
if let tokio_postgres::SimpleQueryMessage::Row(r) = row {
154+
Some(r.get(0).map(|val| val.to_string()))
155+
} else {
156+
None
157+
}
158+
})
159+
.collect()
160+
}
161+
146162
///
147163
/// Configure the client TLS settings.
148164
/// These are the settings for connecting to the database with TLS.

packages/cipherstash-proxy-integration/src/select/group_by.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@ mod tests {
33
use crate::common::{clear, insert, query, random_id, simple_query, trace};
44
use chrono::NaiveDate;
55

6-
macro_rules! value_for_type {
7-
(String, $i:expr) => {
8-
format!("group_{}", $i)
9-
};
10-
11-
(NaiveDate, $i:expr) => {
12-
NaiveDate::parse_from_str(&format!("2023-01-{}", $i), "%Y-%m-%d").unwrap()
13-
};
14-
15-
($type:ident, $i:expr) => {
16-
$i as $type
17-
};
18-
}
19-
206
macro_rules! test_group_by {
217
($name: ident, $type: ident, $pg_type: ident) => {
228
#[tokio::test]
@@ -28,7 +14,7 @@ mod tests {
2814
let encrypted_col = format!("encrypted_{}", stringify!($pg_type));
2915

3016
for i in 1..=10 {
31-
let encrypted_val = value_for_type!($type, i);
17+
let encrypted_val = crate::value_for_type!($type, i);
3218

3319
// Create two records with the same encrypted_int4 value
3420
for _ in 1..=2 {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
mod group_by;
22
mod order_by;
3+
mod order_by_with_null;
4+
5+
#[macro_export]
6+
macro_rules! value_for_type {
7+
(String, $i:expr) => {
8+
format!("group_{}", $i)
9+
};
10+
11+
(NaiveDate, $i:expr) => {
12+
NaiveDate::parse_from_str(&format!("2023-01-{}", $i), "%Y-%m-%d").unwrap()
13+
};
14+
15+
($type:ident, $i:expr) => {
16+
$i as $type
17+
};
18+
}

packages/cipherstash-proxy-integration/src/select/order_by.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@ mod tests {
33
use crate::common::{clear, insert, query, random_id, simple_query, trace};
44
use chrono::NaiveDate;
55

6-
macro_rules! value_for_type {
7-
(String, $i:expr) => {
8-
((b'A' + ($i - 1) as u8) as char).to_string()
9-
};
10-
11-
(NaiveDate, $i:expr) => {
12-
NaiveDate::parse_from_str(&format!("2023-01-{}", $i), "%Y-%m-%d").unwrap()
13-
};
14-
15-
($type:ident, $i:expr) => {
16-
$i as $type
17-
};
18-
}
19-
206
macro_rules! test_order_by {
217
($name: ident, $type: ident, $pg_type: ident) => {
228
#[tokio::test]
@@ -28,7 +14,7 @@ mod tests {
2814

2915
let mut expected = vec![];
3016
for i in 1..=10 {
31-
let encrypted_val = value_for_type!($type, i);
17+
let encrypted_val = crate::value_for_type!($type, i);
3218

3319
let id = random_id();
3420
let sql =

0 commit comments

Comments
 (0)