Skip to content

Commit 940387f

Browse files
committed
Test Postgres more round-trippily
Signed-off-by: itowlson <[email protected]>
1 parent b17f132 commit 940387f

File tree

1 file changed

+34
-7
lines changed
  • tests/test-components/components/outbound-postgres/src

1 file changed

+34
-7
lines changed

tests/test-components/components/outbound-postgres/src/lib.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ impl Component {
2828
ensure!(matches!(rowset.rows[0][0], postgres::DbValue::Str(ref s) if s == "rvarchar"));
2929

3030
let rowset = ensure_ok!(date_time_types(&conn));
31-
ensure!(rowset.rows.iter().all(|r| r.len() == 3));
32-
ensure_matches!(rowset.rows[0][0], postgres::DbValue::Date((y, m, d)) if y == 2525 && m == 12 && d == 25);
31+
ensure!(rowset.rows.iter().all(|r| r.len() == 4));
32+
ensure_matches!(rowset.rows[0][1], postgres::DbValue::Date((y, m, d)) if y == 2525 && m == 12 && d == 25);
33+
ensure_matches!(rowset.rows[0][2], postgres::DbValue::Time((h, m, s, ns)) if h == 4 && m == 5 && s == 6 && ns == 789_000_000);
34+
ensure_matches!(rowset.rows[0][3], postgres::DbValue::Datetime((y, _, _, h, _, _, ns)) if y == 1989 && h == 1 && ns == 0);
35+
ensure_matches!(rowset.rows[1][1], postgres::DbValue::Date((y, m, d)) if y == 2525 && m == 12 && d == 25);
36+
ensure_matches!(rowset.rows[1][2], postgres::DbValue::Time((h, m, s, ns)) if h == 14 && m == 15 && s == 16 && ns == 17);
37+
ensure_matches!(rowset.rows[1][3], postgres::DbValue::Datetime((y, _, _, h, _, _, ns)) if y == 1989 && h == 1 && ns == 4);
3338

3439
let rowset = ensure_ok!(nullable(&conn));
3540
ensure!(rowset.rows.iter().all(|r| r.len() == 1));
@@ -124,6 +129,7 @@ fn character_types(conn: &postgres::Connection) -> Result<postgres::RowSet, post
124129
fn date_time_types(conn: &postgres::Connection) -> Result<postgres::RowSet, postgres::Error> {
125130
let create_table_sql = r#"
126131
CREATE TEMPORARY TABLE test_date_time_types (
132+
index int2,
127133
rdate date NOT NULL,
128134
rtime time NOT NULL,
129135
rtimestamp timestamp NOT NULL
@@ -132,24 +138,45 @@ fn date_time_types(conn: &postgres::Connection) -> Result<postgres::RowSet, post
132138

133139
conn.execute(create_table_sql, &[])?;
134140

135-
let insert_sql = r#"
141+
// We will use this to test that we correctly decode "known good"
142+
// Postgres database values. (This validates our decoding logic
143+
// independently of our encoding logic.)
144+
let insert_sql_pg_literals = r#"
136145
INSERT INTO test_date_time_types
137-
(rdate, rtime, rtimestamp)
146+
(index, rdate, rtime, rtimestamp)
138147
VALUES
139-
(date '2525-12-25', time '04:05:06.789', timestamp '1989-11-24 01:02:03');
148+
(1, date '2525-12-25', time '04:05:06.789', timestamp '1989-11-24 01:02:03');
140149
"#;
141150

142-
conn.execute(insert_sql, &[])?;
151+
conn.execute(insert_sql_pg_literals, &[])?;
152+
153+
// We will use this to test that we correctly encode Spin ParameterValue
154+
// objects. (In conjunction with knowing that our decode logic is good,
155+
// this validates our encode logic.)
156+
let insert_sql_spin_parameters = r#"
157+
INSERT INTO test_date_time_types
158+
(index, rdate, rtime, rtimestamp)
159+
VALUES
160+
(2, $1, $2, $3);
161+
"#;
162+
163+
let date_pv = postgres::ParameterValue::Date((2525, 12, 25));
164+
let time_pv = postgres::ParameterValue::Time((14, 15, 16, 17));
165+
let ts_pv = postgres::ParameterValue::Datetime((1989, 11, 24, 1, 2, 3, 4));
166+
conn.execute(insert_sql_spin_parameters, &[date_pv, time_pv, ts_pv])?;
143167

144168
let sql = r#"
145169
SELECT
170+
index,
146171
rdate,
147172
rtime,
148173
rtimestamp
149-
FROM test_date_time_types;
174+
FROM test_date_time_types
175+
ORDER BY index;
150176
"#;
151177

152178
conn.query(sql, &[])
179+
153180
}
154181

155182
fn nullable(conn: &postgres::Connection) -> Result<postgres::RowSet, postgres::Error> {

0 commit comments

Comments
 (0)