Skip to content

Commit 5198e36

Browse files
committed
chore: rebase + more concise unit tests
1 parent 0a8dc31 commit 5198e36

3 files changed

Lines changed: 20 additions & 43 deletions

File tree

tests/mysql/types.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -387,31 +387,19 @@ CREATE TEMPORARY TABLE user_login (
387387
}
388388

389389
#[sqlx_macros::test]
390-
async fn test_arc_str() -> anyhow::Result<()> {
390+
async fn test_arc_str_slice() -> anyhow::Result<()> {
391391
let mut conn = new::<MySql>().await?;
392392

393393
let name: Arc<str> = "Harold".into();
394+
let slice: Arc<[u8]> = [5, 0].into();
394395

395-
let username: Arc<str> = sqlx::query_scalar("SELECT ? AS username")
396+
let username: (Arc<str>, Arc<[u8]>) = sqlx::query_as("SELECT ?, ?")
396397
.bind(&name)
398+
.bind(&slice)
397399
.fetch_one(&mut conn)
398400
.await?;
399401

400-
assert!(username == name);
401-
Ok(())
402-
}
403-
404-
#[sqlx_macros::test]
405-
async fn test_arc_slice() -> anyhow::Result<()> {
406-
let mut conn = new::<MySql>().await?;
407-
408-
let name: Arc<[u8]> = [5, 0].into();
409-
410-
let username: Arc<[u8]> = sqlx::query_scalar("SELECT ?")
411-
.bind(&name)
412-
.fetch_one(&mut conn)
413-
.await?;
414-
415-
assert!(username == name);
402+
assert!(username.0 == name);
403+
assert!(username.1 == slice);
416404
Ok(())
417405
}

tests/postgres/types.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -704,18 +704,19 @@ async fn test_arc() -> anyhow::Result<()> {
704704
}
705705

706706
#[sqlx_macros::test]
707-
async fn test_arc_slice_2() -> anyhow::Result<()> {
707+
async fn test_arc_str_slice() -> anyhow::Result<()> {
708708
let mut conn = new::<Postgres>().await?;
709709

710-
#[derive(FromRow)]
711-
struct Nested {
712-
inner: Arc<[i32]>,
713-
}
710+
let name: Arc<str> = "Harold".into();
711+
let slice: Arc<[u8]> = [5, 0].into();
714712

715-
let username: Nested = sqlx::query_as("SELECT ARRAY[1, 2, 3]::INT4[] as inner")
713+
let username: (Arc<str>, Arc<[u8]>) = sqlx::query_as("SELECT $1, $2")
714+
.bind(&name)
715+
.bind(&slice)
716716
.fetch_one(&mut conn)
717717
.await?;
718718

719-
assert!(username.inner.as_ref() == &[1, 2, 3]);
719+
assert!(username.0 == name);
720+
assert!(username.1 == slice);
720721
Ok(())
721722
}

tests/sqlite/types.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,31 +253,19 @@ CREATE TEMPORARY TABLE user_login (
253253
}
254254

255255
#[sqlx_macros::test]
256-
async fn test_arc_str() -> anyhow::Result<()> {
256+
async fn test_arc_str_slice() -> anyhow::Result<()> {
257257
let mut conn = new::<Sqlite>().await?;
258258

259259
let name: Arc<str> = "Harold".into();
260+
let slice: Arc<[u8]> = [5, 0].into();
260261

261-
let username: Arc<str> = sqlx::query_scalar("SELECT $1 AS username")
262+
let username: (Arc<str>, Arc<[u8]>) = sqlx::query_as("SELECT $1, $2")
262263
.bind(&name)
264+
.bind(&slice)
263265
.fetch_one(&mut conn)
264266
.await?;
265267

266-
assert!(username == name);
267-
Ok(())
268-
}
269-
270-
#[sqlx_macros::test]
271-
async fn test_arc_slice() -> anyhow::Result<()> {
272-
let mut conn = new::<Sqlite>().await?;
273-
274-
let name: Arc<[u8]> = [5, 0].into();
275-
276-
let username: Arc<[u8]> = sqlx::query_scalar("SELECT $1")
277-
.bind(&name)
278-
.fetch_one(&mut conn)
279-
.await?;
280-
281-
assert!(username == name);
268+
assert!(username.0 == name);
269+
assert!(username.1 == slice);
282270
Ok(())
283271
}

0 commit comments

Comments
 (0)