Skip to content

Commit

Permalink
chore: add postgres tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nlopes committed Sep 10, 2023
1 parent be87051 commit bbfe6e6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
postgresql-version: [14]
toolchain: [ 'stable' ]
nightly: [false]
include:
Expand All @@ -37,6 +38,14 @@ jobs:
rustup run ${{ matrix.toolchain }} cargo --version --verbose
rustup run ${{ matrix.toolchain }} cargo clippy --version
rustup run ${{ matrix.toolchain }} cargo fmt --version
- name: Install PostgreSQL client version matching docker-compose
env:
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install --no-install-recommends "postgresql-client-${POSTGRESQL_VERSION}"
- name: Cache cargo registry
uses: actions/cache@v3
Expand Down Expand Up @@ -67,11 +76,19 @@ jobs:
- name: Run test - mysql | sqlx | runtime-async-std
run: rustup run ${{ matrix.toolchain }} cargo test --features mysql,sqlx,runtime-async-std --all-targets --verbose

- name: Run test - postgres | diesel
run: rustup run ${{ matrix.toolchain }} cargo test --features postgres,diesel --all-targets --verbose

- name: Run test - postgres | sqlx | runtime-async-std
run: |
export PATH="/usr/lib/postgresql/${POSTGRESQL_VERSION}/bin:$PATH"
rustup run ${{ matrix.toolchain }} cargo test --features postgres,sqlx,runtime-async-std --all-targets --verbose
- name: Stop containers for database tests
if: always()
run: |
docker compose -f "docker-compose.yml" down --volumes
sudo rm -rf .data/{postgresql-15,mysql-8}
sudo rm -rf .data/{postgresql-${POSTGRESQL_VERSION},mysql-8}
- name: Run doc tests
run: rustup run ${{ matrix.toolchain }} cargo test --features sqlite,sqlx,runtime-async-std,macros --doc --verbose
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# IMPORTANT: if you change the data folders below, make sure you also change their cleanup
# inside the `.github/workflows/ci.yml` file
services:
postgres-15:
image: postgres:15-alpine
postgres-14:
image: postgres:14-alpine
ports:
- "127.0.0.1:5432:5432"
environment:
- POSTGRES_USER=root
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- .data/postgresql-15/:/var/lib/postgresql
- .data/postgresql-14/:/var/lib/postgresql
mysql-8:
image: mysql:8
ports:
Expand Down
7 changes: 0 additions & 7 deletions fixtures/diesel/postgres/diesel-postgres-structure.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 15.2
-- Dumped by pg_dump version 15.4 (Homebrew)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down
7 changes: 0 additions & 7 deletions fixtures/sqlx/postgres/sqlx-postgres-structure.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 15.2
-- Dumped by pg_dump version 15.4 (Homebrew)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down
10 changes: 6 additions & 4 deletions src/postgres/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implementation of the `postgres` feature
pub(crate) const DEFAULT_CONNECTION_URL: &str = "postgresql://root:@localhost:5432/postgres";
pub(crate) const DEFAULT_CONNECTION_URL: &str = "postgresql://root:@127.0.0.1:5432/postgres";

use crate::error::Error;

Expand Down Expand Up @@ -77,13 +77,15 @@ mod tests {
&destination_path,
)
.await?;
let expected = std::fs::read_to_string(dbg!(format!(
let expected = std::fs::read_to_string(format!(
"./{}/{}",
fixtures_path.as_ref(),
destination_filename.as_ref()
)))?;
))?;
dbg!(&expected);
let contents = std::fs::read_to_string(destination_path)?;
assert_eq!(contents, expected);
dbg!(&contents);
assert!(contents.contains(&expected));
Ok(())
}

Expand Down

0 comments on commit bbfe6e6

Please sign in to comment.