Add some initial type integration tests for Postgres

This commit is contained in:
Ryan Leckey 2019-11-23 09:02:56 +00:00
parent b87edd5a9a
commit ab32d0a5c4
2 changed files with 39 additions and 0 deletions

View file

@ -40,6 +40,10 @@ criterion = "0.3.0"
name = "sql-macro-test"
required-features = ["postgres", "uuid", "macros"]
[[test]]
name = "postgres-types"
required-features = ["postgres"]
[[bench]]
name = "postgres_protocol"
required-features = ["postgres", "unstable"]

35
tests/postgres-types.rs Normal file
View file

@ -0,0 +1,35 @@
use sqlx::{Connection, Postgres};
use std::env;
macro_rules! test {
($name:ident: $ty:ty: $($text:literal == $value:expr),+) => {
#[async_std::test]
async fn $name () -> sqlx::Result<()> {
let mut conn =
Connection::<Postgres>::open(&env::var("DATABASE_URL").unwrap()).await?;
$(
let row = sqlx::query(&format!("SELECT {} = $1, $1", $text))
.bind($value)
.fetch_one(&mut conn)
.await?;
assert!(row.get::<bool>(0));
assert!($value == row.get::<$ty>(1));
)+
Ok(())
}
}
}
test!(postgres_bool: bool: "false::boolean" == false, "true::boolean" == true);
test!(postgres_smallint: i16: "821::smallint" == 821_i16);
test!(postgres_int: i32: "94101::int" == 94101_i32);
test!(postgres_bigint: i64: "9358295312::bigint" == 9358295312_i64);
test!(postgres_real: f32: "9419.122::real" == 9419.122_f32);
test!(postgres_double: f64: "939399419.1225182::double precision" == 939399419.1225182_f64);
test!(postgres_text: String: "'this is foo'" == "this is foo", "''" == "");