11#[ cfg( test) ]
22mod tests {
3- use crate :: common:: { clear, insert, query_by, random_id, random_limited, trace} ;
3+ use crate :: common:: {
4+ clear, insert, insert_simple_query, query_by, random_id, random_limited, simple_query,
5+ trace,
6+ } ;
47 use chrono:: NaiveDate ;
58 use serde_json:: Value ;
69
@@ -17,14 +20,42 @@ mod tests {
1720 let encrypted_col = format!( "encrypted_{}" , stringify!( $pg_type) ) ;
1821 let encrypted_val = crate :: value_for_type!( $type, random_limited( ) ) ;
1922
20- let sql = format!( "INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, '{encrypted_val}')" ) ;
21- insert( & sql, & [ & id] ) . await ;
23+ let expected = vec![ encrypted_val. clone( ) ] ;
2224
23- let expected = vec![ encrypted_val] ;
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" ) ;
27+
28+ insert( & insert_sql, & [ & id] ) . await ;
29+ let actual = query_by:: <$type>( & select_sql, & id) . await ;
30+
31+ assert_eq!( expected, actual) ;
2432
25- let sql = format!( "SELECT {encrypted_col} FROM encrypted WHERE id = $1" ) ;
33+ }
34+ } ;
35+ }
2636
27- let actual = query_by:: <$type>( & sql, & id) . await ;
37+ macro_rules! test_insert_simple_query_with_literal {
38+ ( $name: ident, $type: ident, $pg_type: ident) => {
39+ #[ tokio:: test]
40+ pub async fn $name( ) {
41+ trace( ) ;
42+
43+ clear( ) . await ;
44+
45+
46+ let id = random_id( ) ;
47+
48+ let encrypted_col = format!( "encrypted_{}" , stringify!( $pg_type) ) ;
49+ let encrypted_val = crate :: value_for_type!( $type, random_limited( ) ) ;
50+
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}" ) ;
53+
54+
55+ let expected = vec![ encrypted_val] ;
56+
57+ insert_simple_query( & insert_sql) . await ;
58+ let actual = simple_query:: <$type>( & select_sql) . await ;
2859
2960 assert_eq!( expected, actual) ;
3061 }
@@ -40,6 +71,15 @@ mod tests {
4071 test_insert_with_literal ! ( insert_with_literal_date, NaiveDate , date) ;
4172 test_insert_with_literal ! ( insert_with_literal_jsonb, Value , jsonb) ;
4273
74+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_int2, i16 , int2) ;
75+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_int4, i32 , int4) ;
76+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_int8, i64 , int8) ;
77+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_float8, f64 , float8) ;
78+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_bool, bool , bool ) ;
79+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_text, String , text) ;
80+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_date, NaiveDate , date) ;
81+ test_insert_simple_query_with_literal ! ( insert_simple_query_with_literal_jsonb, Value , jsonb) ;
82+
4383 // -----------------------------------------------------------------
4484
4585 /// Sanity check insert of unencrypted literal value
0 commit comments