diff --git a/tests/postgres-macros.rs b/tests/postgres-macros.rs index 07250cd1..0d6e89d5 100644 --- a/tests/postgres-macros.rs +++ b/tests/postgres-macros.rs @@ -1,9 +1,10 @@ -use sqlx::{Connect, PgConnection}; +use sqlx::Postgres; +use sqlx_test::new; #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let account = sqlx::query!( "SELECT * from (VALUES (1, 'Herp Derpinson')) accounts(id, name) where id = $1", @@ -20,7 +21,7 @@ async fn test_query() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_no_result() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let _ = sqlx::query!("DELETE FROM pg_enum") .execute(&mut conn) @@ -32,7 +33,7 @@ async fn test_no_result() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_text_var_char_char_n() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; // TEXT // we cannot infer nullability from an expression @@ -64,7 +65,7 @@ async fn test_text_var_char_char_n() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn _file() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let account = sqlx::query_file!("tests/test-query.sql",) .fetch_one(&mut conn) @@ -84,7 +85,7 @@ struct Account { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query_as() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let name: Option<&str> = None; let account = sqlx::query_as!( @@ -111,7 +112,7 @@ struct RawAccount { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query_as_raw() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let account = sqlx::query_as!( RawAccount, @@ -131,7 +132,7 @@ async fn test_query_as_raw() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query_file_as() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let account = sqlx::query_file_as!(Account, "tests/test-query.sql",) .fetch_one(&mut conn) @@ -145,7 +146,7 @@ async fn test_query_file_as() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn query_by_string() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let string = "Hello, world!".to_string(); let ref tuple = ("Hello, world!".to_string(),); @@ -178,7 +179,7 @@ async fn test_nullable_err() -> anyhow::Result<()> { name: String, } - let mut conn = connect().await?; + let mut conn = new::().await?; let err = sqlx::query_as!( Account, @@ -200,7 +201,7 @@ async fn test_nullable_err() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_many_args() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; // previous implementation would only have supported 10 bind parameters // (this is really gross to test in MySQL) @@ -221,7 +222,7 @@ async fn test_many_args() -> anyhow::Result<()> { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_array_from_slice() -> anyhow::Result<()> { - let mut conn = connect().await?; + let mut conn = new::().await?; let list: &[i32] = &[1, 2, 3, 4i32]; @@ -243,10 +244,3 @@ async fn test_array_from_slice() -> anyhow::Result<()> { Ok(()) } - -async fn connect() -> anyhow::Result { - let _ = dotenv::dotenv(); - let _ = env_logger::try_init(); - - Ok(PgConnection::connect(dotenv::var("DATABASE_URL")?).await?) -} diff --git a/tests/postgres-types.rs b/tests/postgres-types.rs index c3b4d6bf..83f1370f 100644 --- a/tests/postgres-types.rs +++ b/tests/postgres-types.rs @@ -11,6 +11,7 @@ use sqlx_test::{new, test_prepared_type, test_type}; macro_rules! array_macro_test { ($name:ident($type:ty, $($sql:literal == $value:expr),+ $(,)?)) => { paste::item! { + #[allow(unused_imports)] #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn [< test_array_type_ $name >] () -> anyhow::Result<()> { @@ -688,8 +689,6 @@ mod json { #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_json_value_in_macro() -> anyhow::Result<()> { - use sqlx::prelude::*; - let mut conn = sqlx_test::new::().await?; let v: serde_json::Value = json!({