Skip to content

Commit

Permalink
fix(tests): fix tests rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Feb 4, 2023
1 parent b98e986 commit 8ac8749
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ jobs:
--features any,mysql,macros,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?ssl-mode=disabled
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# MySQL 5.7 supports TLS but not TLSv1.3 as required by RusTLS.
- uses: actions-rs/cargo@v1
Expand All @@ -282,6 +283,7 @@ jobs:
--features any,mysql,macros,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

mariadb:
name: MariaDB
Expand Down Expand Up @@ -322,3 +324,4 @@ jobs:
--features any,mysql,macros,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx
RUSTFLAGS: --cfg mariadb_${{ matrix.mariadb }}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ name = "sqlite-derives"
path = "tests/sqlite/derives.rs"
required-features = ["sqlite", "macros"]

[[test]]
name = "sqlite-error"
path = "tests/sqlite/error.rs"
required-features = ["sqlite"]
Expand Down
41 changes: 0 additions & 41 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,44 +173,3 @@ services:
- "./postgres/setup.sql:/docker-entrypoint-initdb.d/setup.sql"
command: >
-c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
#
# Microsoft SQL Server (MSSQL)
# https://hub.docker.com/_/microsoft-mssql-server
#

mssql_2019:
build:
context: .
dockerfile: mssql/Dockerfile
args:
VERSION: 2019-latest
ports:
- 1433
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: Password123!

mssql_2017:
build:
context: .
dockerfile: mssql/mssql-2017.dockerfile
args:
VERSION: 2017-latest
ports:
- 1433
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: Password123!

#
# IBM Db2
# https://hub.docker.com/r/ibmcom/db2
#

db2_11:
image: ibmcom/db2:11.5.1.0-CN1
privileged: true
environment:
LICENSE: accept
DB2INST1_PASSWORD: password
DBNAME: sqlx
23 changes: 10 additions & 13 deletions tests/mysql/error.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use sqlx::{error::ErrorKind, mysql::MySql, Connection, Executor, Transaction};
use sqlx::{error::ErrorKind, mysql::MySql, Connection};
use sqlx_test::new;

async fn with_test_row(conn: &mut Transaction<'_, MySql>) -> anyhow::Result<()> {
sqlx::query!("INSERT INTO tweet(id, text, owner_id) VALUES (1, 'Foo', 1)")
.execute(conn)
.await?;
Ok(())
}

#[sqlx_macros::test]
async fn it_fails_with_unique_violation() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;
let mut tx = conn.begin().await?;
with_test_row(&mut tx).await.unwrap();

sqlx::query("INSERT INTO tweet(id, text, owner_id) VALUES (1, 'Foo', 1)")
.execute(&mut *tx)
.await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet VALUES (1, NOW(), 'Foo', 1);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -33,7 +29,7 @@ async fn it_fails_with_foreign_key_violation() -> anyhow::Result<()> {

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO tweet_reply (tweet_id, text) VALUES (1, 'Reply!');")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -50,7 +46,7 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> {
let mut tx = conn.begin().await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet (text) VALUES (null);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -61,14 +57,15 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> {
Ok(())
}

#[cfg(mysql_8)]
#[sqlx_macros::test]
async fn it_fails_with_check_violation() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;
let mut tx = conn.begin().await?;

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO products VALUES (1, 'Product 1', 0);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand Down
22 changes: 9 additions & 13 deletions tests/postgres/error.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use sqlx::{error::ErrorKind, postgres::Postgres, Connection, Executor, Transaction};
use sqlx::{error::ErrorKind, postgres::Postgres, Connection};
use sqlx_test::new;

async fn with_test_row(conn: &mut Transaction<'_, Postgres>) -> anyhow::Result<()> {
sqlx::query!("INSERT INTO tweet(id, text, owner_id) VALUES (1, 'Foo', 1)")
.execute(conn)
.await?;
Ok(())
}

#[sqlx_macros::test]
async fn it_fails_with_unique_violation() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().await?;
let mut tx = conn.begin().await?;
with_test_row(&mut tx).await.unwrap();

sqlx::query("INSERT INTO tweet(id, text, owner_id) VALUES (1, 'Foo', 1);")
.execute(&mut *tx)
.await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet VALUES (1, NOW(), 'Foo', 1);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -33,7 +29,7 @@ async fn it_fails_with_foreign_key_violation() -> anyhow::Result<()> {

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO tweet_reply (tweet_id, text) VALUES (1, 'Reply!');")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -50,7 +46,7 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> {
let mut tx = conn.begin().await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet (text) VALUES (null);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -68,7 +64,7 @@ async fn it_fails_with_check_violation() -> anyhow::Result<()> {

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO products VALUES (1, 'Product 1', 0);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand Down
8 changes: 4 additions & 4 deletions tests/sqlite/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async fn it_fails_with_unique_violation() -> anyhow::Result<()> {
let mut tx = conn.begin().await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet VALUES (1, 'Foo', true, 1);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -25,7 +25,7 @@ async fn it_fails_with_foreign_key_violation() -> anyhow::Result<()> {

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO tweet_reply (id, tweet_id, text) VALUES (2, 2, 'Reply!');")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -42,7 +42,7 @@ async fn it_fails_with_not_null_violation() -> anyhow::Result<()> {
let mut tx = conn.begin().await?;

let res: Result<_, sqlx::Error> = sqlx::query("INSERT INTO tweet (text) VALUES (null);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand All @@ -60,7 +60,7 @@ async fn it_fails_with_check_violation() -> anyhow::Result<()> {

let res: Result<_, sqlx::Error> =
sqlx::query("INSERT INTO products VALUES (1, 'Product 1', 0);")
.execute(&mut tx)
.execute(&mut *tx)
.await;
let err = res.unwrap_err();

Expand Down
Binary file modified tests/sqlite/sqlite.db
Binary file not shown.
38 changes: 13 additions & 25 deletions tests/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data
# check
#

for runtime in ["async-std", "tokio", "actix"]:
for tls in ["native-tls", "rustls"]:
for runtime in ["async-std", "tokio"]:
for tls in ["native-tls", "rustls", "none"]:
run(
f"cargo c --no-default-features --features all-databases,all-types,offline,macros,runtime-{runtime}-{tls}",
f"cargo c --no-default-features --features all-databases,_unstable-all-types,macros,runtime-{runtime},tls-{tls}",
comment="check with async-std",
tag=f"check_{runtime}_{tls}"
)
Expand All @@ -139,10 +139,10 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data
# unit test
#

for runtime in ["async-std", "tokio", "actix"]:
for tls in ["native-tls", "rustls"]:
for runtime in ["async-std", "tokio"]:
for tls in ["native-tls", "rustls", "none"]:
run(
f"cargo test --no-default-features --manifest-path sqlx-core/Cargo.toml --features all-databases,all-types,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --manifest-path sqlx-core/Cargo.toml --features json,offline,migrate,_rt-{runtime},_tls-{tls}",
comment="unit test core",
tag=f"unit_{runtime}_{tls}"
)
Expand All @@ -151,15 +151,15 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data
# integration tests
#

for runtime in ["async-std", "tokio", "actix"]:
for tls in ["native-tls", "rustls"]:
for runtime in ["async-std", "tokio"]:
for tls in ["native-tls", "rustls", "none"]:

#
# sqlite
#

run(
f"cargo test --no-default-features --features macros,offline,any,all-types,sqlite,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --features macros,any,_unstable-all-types,sqlite,runtime-{runtime},tls-{tls}",
comment=f"test sqlite",
service="sqlite",
tag=f"sqlite" if runtime == "async-std" else f"sqlite_{runtime}",
Expand All @@ -171,7 +171,7 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data

for version in ["14", "13", "12", "11", "10"]:
run(
f"cargo test --no-default-features --features macros,offline,any,all-types,postgres,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --features macros,any,unstable-all-types,postgres,runtime-{runtime},tls-{tls}",
comment=f"test postgres {version}",
service=f"postgres_{version}",
tag=f"postgres_{version}" if runtime == "async-std" else f"postgres_{version}_{runtime}",
Expand All @@ -180,7 +180,7 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data
## +ssl
for version in ["14", "13", "12", "11", "10"]:
run(
f"cargo test --no-default-features --features macros,offline,any,all-types,postgres,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --features macros,any,_unstable-all-types,postgres,runtime-{runtime},tls-{tls}",
comment=f"test postgres {version} ssl",
database_url_args="sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt",
service=f"postgres_{version}",
Expand All @@ -193,7 +193,7 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data

for version in ["8", "5_7"]:
run(
f"cargo test --no-default-features --features macros,offline,any,all-types,mysql,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --features macros,any,_unstable-all-types,mysql,runtime-{runtime},tls-{tls}",
comment=f"test mysql {version}",
service=f"mysql_{version}",
tag=f"mysql_{version}" if runtime == "async-std" else f"mysql_{version}_{runtime}",
Expand All @@ -205,23 +205,11 @@ def run(command, comment=None, env=None, service=None, tag=None, args=None, data

for version in ["10_6", "10_5", "10_4", "10_3", "10_2"]:
run(
f"cargo test --no-default-features --features macros,offline,any,all-types,mysql,runtime-{runtime}-{tls}",
f"cargo test --no-default-features --features macros,any,_unstable-all-types,mysql,runtime-{runtime},tls-{tls}",
comment=f"test mariadb {version}",
service=f"mariadb_{version}",
tag=f"mariadb_{version}" if runtime == "async-std" else f"mariadb_{version}_{runtime}",
)

#
# mssql
#

for version in ["2019", "2017"]:
run(
f"cargo test --no-default-features --features macros,offline,any,all-types,mssql,runtime-{runtime}-{tls}",
comment=f"test mssql {version}",
service=f"mssql_{version}",
tag=f"mssql_{version}" if runtime == "async-std" else f"mssql_{version}_{runtime}",
)

# TODO: Use [grcov] if available
# ~/.cargo/bin/grcov tests/.cache/target/debug -s sqlx-core/ -t html --llvm --branch -o ./target/debug/coverage

0 comments on commit 8ac8749

Please sign in to comment.