mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
Add some initial type integration tests for Postgres
This commit is contained in:
parent
b87edd5a9a
commit
ab32d0a5c4
2 changed files with 39 additions and 0 deletions
|
@ -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
35
tests/postgres-types.rs
Normal 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", "''" == "");
|
Loading…
Reference in a new issue