Skip to content

Commit 4a8f2e1

Browse files
committed
test(postgres): cover empty single-row queries
1 parent d77d5aa commit 4a8f2e1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎tests/crud/read_operations.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ fn test_crud_find_by_pk() {
7676
);
7777
}
7878

79+
/// PostgreSQL must represent an empty result as `Ok(None)` instead of deriving
80+
/// control flow from the driver's error text.
81+
#[cfg(feature = "postgres")]
82+
#[canyon_sql::macros::canyon_tokio_test]
83+
fn test_crud_find_by_pk_returns_none_when_postgres_has_no_rows() {
84+
let find_by_pk_result: canyon_sql::CanyonResult<Option<League>> =
85+
League::find_by_pk(&i32::MIN).await;
86+
87+
assert_eq!(find_by_pk_result.unwrap(), None);
88+
}
89+
7990
/// Tests the behaviour of a SELECT * FROM {table_name} WHERE <pk> = <pk_value>, where the pk is
8091
/// defined with the #[primary_key] attribute over some field of the type.
8192
///

0 commit comments

Comments
 (0)