Skip to content

Commit bbc90b4

Browse files
committed
Fix tests
1 parent ccd6000 commit bbc90b4

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub use self::run_query_dsl::*;
2020
pub use self::stmt_cache::StmtCache;
2121
pub use self::transaction_manager::{AnsiTransactionManager, TransactionManager};
2222

23-
2423
#[async_trait::async_trait]
2524
pub trait SimpleAsyncConnection {
2625
async fn batch_execute(&mut self, query: &str) -> QueryResult<()>;

src/mysql/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ impl AsyncMysqlConnection {
146146
];
147147

148148
for stmt in setup_statements {
149-
diesel::sql_query(stmt).execute(&mut conn)
149+
diesel::sql_query(stmt)
150+
.execute(&mut conn)
150151
.await
151152
.map_err(ConnectionError::CouldntSetupConfiguration)?;
152153
}

src/pg/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ impl AsyncPgConnection {
207207
async fn set_config_options(&mut self) -> QueryResult<()> {
208208
use crate::run_query_dsl::RunQueryDsl;
209209

210-
diesel::sql_query("SET TIME ZONE 'UTC'").execute(self).await?;
211-
diesel::sql_query("SET CLIENT_ENCODING TO 'UTF8'").execute(self).await?;
210+
diesel::sql_query("SET TIME ZONE 'UTC'")
211+
.execute(self)
212+
.await?;
213+
diesel::sql_query("SET CLIENT_ENCODING TO 'UTF8'")
214+
.execute(self)
215+
.await?;
212216
Ok(())
213217
}
214218

@@ -232,9 +236,7 @@ impl AsyncPgConnection {
232236
let res = query.collect_binds(&mut bind_collector, self, &diesel::pg::Pg);
233237

234238
if !self.next_lookup.is_empty() {
235-
for (schema, lookup_type_name) in
236-
std::mem::take(&mut self.next_lookup)
237-
{
239+
for (schema, lookup_type_name) in std::mem::take(&mut self.next_lookup) {
238240
// as this is an async call and we don't want to infect the whole diesel serialization
239241
// api with async we just error out in the `PgMetadataLookup` implementation below if we encounter
240242
// a type that is not cached yet

tests/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,36 @@ async fn test_basic_insert_and_load() -> QueryResult<()> {
7777
Ok(())
7878
}
7979

80+
#[cfg(feature = "mysql")]
81+
async fn setup(connection: &mut TestConnection) -> TestConnection {
82+
diesel::sql_query(
83+
"CREATE TABLE IF NOT EXISTS users (
84+
id INTEGER PRIMARY KEY AUTO_INCREMENT,
85+
name TEXT NOT NULL
86+
) CHARACTER SET utf8mb4",
87+
)
88+
.execute(&mut connection)
89+
.await
90+
.unwrap();
91+
}
92+
93+
#[cfg(feature = "postgres")]
94+
async fn setup(connection: &mut TestConnection) -> TestConnection {
95+
diesel::sql_query(
96+
"CREATE TABLE IF NOT EXISTS users (
97+
id SERIAL PRIMARY KEY,
98+
name VARCHAR NOT NULL
99+
)",
100+
)
101+
.execute(&mut connection)
102+
.await
103+
.unwrap();
104+
}
105+
80106
async fn connection() -> TestConnection {
81107
let db_url = std::env::var("DATABASE_URL").unwrap();
82108
let mut conn = TestConnection::establish(&db_url).await.unwrap();
83109
conn.begin_test_transaction().await.unwrap();
110+
setup(&mut conn);
84111
conn
85112
}

0 commit comments

Comments
 (0)