Skip to content

Commit

Permalink
Merge pull request #6 from nlopes/nlopes-add-postgres-tests-to-ci
Browse files Browse the repository at this point in the history
chore: add postgres tests to CI
  • Loading branch information
nlopes authored Sep 10, 2023
2 parents be87051 + 91ba34e commit 051e6a8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 100 deletions.
22 changes: 21 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,22 @@ 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
psql "postgresql://root:@127.0.0.1:5432/postgres" -c "DROP TABLE __diesel_schema_migrations,diesel_users"
- 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
psql "postgresql://root:@127.0.0.1:5432/postgres" -c "DROP TABLE _sqlx_migrations,sqlx_users"
- 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
48 changes: 0 additions & 48 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 All @@ -30,20 +23,6 @@ CREATE TABLE public.__diesel_schema_migrations (
);


--
-- Name: _sqlx_migrations; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public._sqlx_migrations (
version bigint NOT NULL,
description text NOT NULL,
installed_on timestamp with time zone DEFAULT now() NOT NULL,
success boolean NOT NULL,
checksum bytea NOT NULL,
execution_time bigint NOT NULL
);


--
-- Name: diesel_users; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -55,17 +34,6 @@ CREATE TABLE public.diesel_users (
);


--
-- Name: sqlx_users; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.sqlx_users (
id character varying(32) NOT NULL,
email text NOT NULL,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


--
-- Name: __diesel_schema_migrations __diesel_schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand All @@ -74,14 +42,6 @@ ALTER TABLE ONLY public.__diesel_schema_migrations
ADD CONSTRAINT __diesel_schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: _sqlx_migrations _sqlx_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public._sqlx_migrations
ADD CONSTRAINT _sqlx_migrations_pkey PRIMARY KEY (version);


--
-- Name: diesel_users diesel_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand All @@ -90,14 +50,6 @@ ALTER TABLE ONLY public.diesel_users
ADD CONSTRAINT diesel_users_pkey PRIMARY KEY (id);


--
-- Name: sqlx_users sqlx_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sqlx_users
ADD CONSTRAINT sqlx_users_pkey PRIMARY KEY (id);


--
-- PostgreSQL database dump complete
--
Expand Down
44 changes: 0 additions & 44 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 All @@ -20,16 +13,6 @@ SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: __diesel_schema_migrations; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.__diesel_schema_migrations (
version character varying(50) NOT NULL,
run_on timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


--
-- Name: _sqlx_migrations; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -44,17 +27,6 @@ CREATE TABLE public._sqlx_migrations (
);


--
-- Name: diesel_users; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.diesel_users (
id text NOT NULL,
email text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: sqlx_users; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -66,14 +38,6 @@ CREATE TABLE public.sqlx_users (
);


--
-- Name: __diesel_schema_migrations __diesel_schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.__diesel_schema_migrations
ADD CONSTRAINT __diesel_schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: _sqlx_migrations _sqlx_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand All @@ -82,14 +46,6 @@ ALTER TABLE ONLY public._sqlx_migrations
ADD CONSTRAINT _sqlx_migrations_pkey PRIMARY KEY (version);


--
-- Name: diesel_users diesel_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.diesel_users
ADD CONSTRAINT diesel_users_pkey PRIMARY KEY (id);


--
-- Name: sqlx_users sqlx_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down
8 changes: 4 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,13 @@ 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()
)))?;
))?;
let contents = std::fs::read_to_string(destination_path)?;
assert_eq!(contents, expected);
assert!(contents.contains(&expected));
Ok(())
}

Expand Down

0 comments on commit 051e6a8

Please sign in to comment.