Skip to content

Commit 5f54186

Browse files
committed
test(integration): remove jsonb type casting from literal tests
Simplify integration tests by removing unnecessary ::jsonb type casts from INSERT and SELECT statements. The test macros no longer require the $cast parameter since jsonb columns don't need explicit casting.
1 parent 144d8fe commit 5f54186

File tree

3 files changed

+23
-70
lines changed

3 files changed

+23
-70
lines changed

packages/cipherstash-proxy-integration/src/insert/insert_with_literal.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ mod tests {
99

1010
macro_rules! test_insert_with_literal {
1111
($name: ident, $type: ident, $pg_type: ident) => {
12-
test_insert_with_literal!($name, $type, $pg_type, false);
13-
};
14-
15-
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
1612
#[tokio::test]
1713
pub async fn $name() {
1814
trace();
@@ -26,14 +22,8 @@ mod tests {
2622

2723
let expected = vec![encrypted_val.clone()];
2824

29-
let cast_to_type: &str = if $cast {
30-
&format!("::{}", stringify!($pg_type))
31-
} else {
32-
""
33-
};
34-
35-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, '{encrypted_val}'{cast_to_type})");
36-
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = $1");
25+
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, '{encrypted_val}')");
26+
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = $1");
3727

3828
execute_query(&insert_sql, &[&id]).await;
3929
let actual = query_by::<$type>(&select_sql, &id).await;
@@ -46,10 +36,6 @@ mod tests {
4636

4737
macro_rules! test_insert_simple_query_with_literal {
4838
($name: ident, $type: ident, $pg_type: ident) => {
49-
test_insert_simple_query_with_literal!($name, $type, $pg_type, false);
50-
};
51-
52-
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
5339
#[tokio::test]
5440
pub async fn $name() {
5541
trace();
@@ -62,15 +48,8 @@ mod tests {
6248
let encrypted_col = format!("encrypted_{}", stringify!($pg_type));
6349
let encrypted_val = crate::value_for_type!($type, random_limited());
6450

65-
let cast_to_type: &str = if $cast {
66-
&format!("::{}", stringify!($pg_type))
67-
} else {
68-
""
69-
};
70-
71-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{encrypted_val}'{cast_to_type})");
72-
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = {id}");
73-
51+
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{encrypted_val}')");
52+
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = {id}");
7453

7554
let expected = vec![encrypted_val];
7655

@@ -89,7 +68,7 @@ mod tests {
8968
test_insert_with_literal!(insert_with_literal_bool, bool, bool);
9069
test_insert_with_literal!(insert_with_literal_text, String, text);
9170
test_insert_with_literal!(insert_with_literal_date, NaiveDate, date);
92-
test_insert_with_literal!(insert_with_literal_jsonb, Value, jsonb, true);
71+
test_insert_with_literal!(insert_with_literal_jsonb, Value, jsonb);
9372

9473
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_int2, i16, int2);
9574
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_int4, i32, int4);
@@ -98,12 +77,7 @@ mod tests {
9877
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_bool, bool, bool);
9978
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_text, String, text);
10079
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_date, NaiveDate, date);
101-
test_insert_simple_query_with_literal!(
102-
insert_simple_query_with_literal_jsonb,
103-
Value,
104-
jsonb,
105-
true
106-
);
80+
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_jsonb, Value, jsonb);
10781

10882
// -----------------------------------------------------------------
10983

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#[cfg(test)]
22
mod tests {
3-
use crate::common::{clear, connect_with_tls, random_id, PROXY};
3+
use tracing::error;
4+
5+
use crate::common::{clear, connect_with_tls, random_id, trace, PROXY};
46

57
#[tokio::test]
68
async fn map_literal() {
@@ -47,6 +49,7 @@ mod tests {
4749

4850
#[tokio::test]
4951
async fn map_jsonb() {
52+
trace();
5053
clear().await;
5154

5255
let client = connect_with_tls(PROXY).await;
@@ -55,12 +58,12 @@ mod tests {
5558
let encrypted_jsonb = serde_json::json!({"key": "value"});
5659

5760
let sql = format!(
58-
"INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, '{encrypted_jsonb}'::jsonb)",
61+
"INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, '{encrypted_jsonb}')",
5962
);
6063

6164
client.query(&sql, &[&id]).await.unwrap();
6265

63-
let sql = "SELECT id, encrypted_jsonb::jsonb FROM encrypted WHERE id = $1";
66+
let sql = "SELECT id, encrypted_jsonb FROM encrypted WHERE id = $1";
6467
let rows = client.query(sql, &[&id]).await.unwrap();
6568

6669
assert_eq!(rows.len(), 1);

packages/cipherstash-proxy-integration/src/update/update_with_literal.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ mod tests {
99

1010
macro_rules! test_update_with_literal {
1111
($name: ident, $type: ident, $pg_type: ident) => {
12-
test_update_with_literal!($name, $type, $pg_type, false);
13-
};
14-
15-
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
1612
#[tokio::test]
1713
pub async fn $name() {
1814
trace();
@@ -27,35 +23,27 @@ mod tests {
2723

2824
let expected = vec![encrypted_val.clone()];
2925

30-
let cast_to_type: &str = if $cast {
31-
&format!("::{}", stringify!($pg_type))
32-
} else {
33-
""
34-
};
35-
3626
// First insert a record
37-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, $2)");
27+
let insert_sql =
28+
format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, $2)");
3829
execute_query(&insert_sql, &[&id, &initial_val]).await;
3930

4031
// Then update it with literal value
41-
let update_sql = format!("UPDATE encrypted SET {encrypted_col} = '{encrypted_val}'{cast_to_type} WHERE id = $1");
42-
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = $1");
32+
let update_sql = format!(
33+
"UPDATE encrypted SET {encrypted_col} = '{encrypted_val}' WHERE id = $1"
34+
);
35+
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = $1");
4336

4437
execute_query(&update_sql, &[&id]).await;
4538
let actual = query_by::<$type>(&select_sql, &id).await;
4639

4740
assert_eq!(expected, actual);
48-
4941
}
5042
};
5143
}
5244

5345
macro_rules! test_update_simple_query_with_literal {
5446
($name: ident, $type: ident, $pg_type: ident) => {
55-
test_update_simple_query_with_literal!($name, $type, $pg_type, false);
56-
};
57-
58-
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
5947
#[tokio::test]
6048
pub async fn $name() {
6149
trace();
@@ -69,20 +57,13 @@ mod tests {
6957
let initial_val = crate::value_for_type!($type, 1);
7058
let encrypted_val = crate::value_for_type!($type, random_limited());
7159

72-
let cast_to_type: &str = if $cast {
73-
&format!("::{}", stringify!($pg_type))
74-
} else {
75-
""
76-
};
77-
7860
// First insert a record
79-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{initial_val}'{cast_to_type})");
61+
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{initial_val}')");
8062
execute_simple_query(&insert_sql).await;
8163

8264
// Then update it with literal value
83-
let update_sql = format!("UPDATE encrypted SET {encrypted_col} = '{encrypted_val}'{cast_to_type} WHERE id = {id}");
84-
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = {id}");
85-
65+
let update_sql = format!("UPDATE encrypted SET {encrypted_col} = '{encrypted_val}' WHERE id = {id}");
66+
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = {id}");
8667

8768
let expected = vec![encrypted_val];
8869

@@ -101,7 +82,7 @@ mod tests {
10182
test_update_with_literal!(update_with_literal_bool, bool, bool);
10283
test_update_with_literal!(update_with_literal_text, String, text);
10384
test_update_with_literal!(update_with_literal_date, NaiveDate, date);
104-
test_update_with_literal!(update_with_literal_jsonb, Value, jsonb, true);
85+
test_update_with_literal!(update_with_literal_jsonb, Value, jsonb);
10586

10687
test_update_simple_query_with_literal!(update_simple_query_with_literal_int2, i16, int2);
10788
test_update_simple_query_with_literal!(update_simple_query_with_literal_int4, i32, int4);
@@ -110,12 +91,7 @@ mod tests {
11091
test_update_simple_query_with_literal!(update_simple_query_with_literal_bool, bool, bool);
11192
test_update_simple_query_with_literal!(update_simple_query_with_literal_text, String, text);
11293
test_update_simple_query_with_literal!(update_simple_query_with_literal_date, NaiveDate, date);
113-
test_update_simple_query_with_literal!(
114-
update_simple_query_with_literal_jsonb,
115-
Value,
116-
jsonb,
117-
true
118-
);
94+
test_update_simple_query_with_literal!(update_simple_query_with_literal_jsonb, Value, jsonb);
11995

12096
// -----------------------------------------------------------------
12197

0 commit comments

Comments
 (0)