add regression test for Map::fetch() being Unpin

This commit is contained in:
Austin Bonander 2020-04-13 13:37:54 -07:00 committed by Ryan Leckey
parent 8deb5549b3
commit f00b7b48e1

View file

@ -1,6 +1,8 @@
use sqlx::Postgres;
use sqlx_test::new;
use futures::TryStreamExt;
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
async fn test_query() -> anyhow::Result<()> {
@ -244,3 +246,21 @@ async fn test_array_from_slice() -> anyhow::Result<()> {
Ok(())
}
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
async fn fetch_is_usable_issue_224() -> anyhow::Result<()> {
// ensures that the stream returned by `query::Map::fetch()` is usable with `TryStreamExt`
let mut conn = new::<Postgres>().await?;
let mut stream =
sqlx::query!("select * from generate_series(1, 3) as series(num);").fetch(&mut conn);
// `num` is generated by a function so we can't assume it's non-null
assert_eq!(stream.try_next().await?.unwrap().num, Some(1));
assert_eq!(stream.try_next().await?.unwrap().num, Some(2));
assert_eq!(stream.try_next().await?.unwrap().num, Some(3));
assert!(stream.try_next().await?.is_none());
Ok(())
}