Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 139 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,59 +48,175 @@ jobs:
test-postgres:
name: postgres integration test
runs-on: ubuntu-24.04
env:
MIX_ENV: test
ELIXIR_ASSERT_TIMEOUT: 10000
ECTO_ADAPTER: pg
PG_URL: postgres:postgres@127.0.0.1
POOL_COUNT: ${{ matrix.pool_count }}
strategy:
fail-fast: false
matrix:
elixirbase:
- "1.15.6-erlang-25.3.2.6-alpine-3.18.4"
elixir: ["1.15.6"]
otp: ["25.3.2.6"]
postgres:
- "16.2-alpine"
- "11.11-alpine"
- "9.6-alpine"
pool_count:
- "1"
pool_count: ["1"]
include:
- elixirbase: "1.15.6-erlang-25.3.2.6-alpine-3.18.4"
- elixir: "1.15.6"
otp: "25.3.2.6"
postgres: "16.2-alpine"
pool_count: "4"
steps:
- uses: earthly/actions-setup@v1
- uses: actions/checkout@v7
- name: test ecto_sql
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POOL_COUNT: ${{ matrix.pool_count || '1' }}
run: earthly -P --ci --build-arg ELIXIR_BASE=${{matrix.elixirbase}} --build-arg POSTGRES=${{matrix.postgres}} +integration-test-postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 2s
--health-timeout 5s
--health-retries 30
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install Elixir and Erlang
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore deps and _build cache
uses: actions/cache@v6
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test

test-mysql:
name: mysql integration test
runs-on: ubuntu-24.04
env:
MIX_ENV: test
ELIXIR_ASSERT_TIMEOUT: 10000
ECTO_ADAPTER: myxql
MYSQL_URL: root:root@127.0.0.1
strategy:
fail-fast: false
matrix:
elixirbase:
- "1.15.6-erlang-25.3.2.6-alpine-3.18.4"
elixir: ["1.15.6"]
otp: ["25.3.2.6"]
mysql:
- "5.7"
- "8.0"
steps:
- uses: earthly/actions-setup@v1
- uses: actions/checkout@v7
- name: test ecto_sql
run: earthly -P --ci --build-arg ELIXIR_BASE=${{matrix.elixirbase}} --build-arg MYSQL=${{matrix.mysql}} +integration-test-mysql
- name: Start mysql
run: |
# The default authentication plugin for MySQL 8 is sha 256 but it
# doesn't come with the docker image, so we fall back to the 5.7 way
docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root "mysql:${{ matrix.mysql }}" \
--sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES" \
--default-authentication-plugin=mysql_native_password
# The mysqldump 8 client on the runner queries column statistics,
# which do not exist in MySQL 5.7
printf '[mysqldump]\ncolumn-statistics=0\n' > ~/.my.cnf
- name: Checkout
uses: actions/checkout@v7
- name: Install Elixir and Erlang
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore deps and _build cache
uses: actions/cache@v6
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-
- name: Install dependencies
run: mix deps.get
- name: Wait for mysql
run: |
for i in $(seq 1 60); do
mysqladmin ping --host=127.0.0.1 --port=3306 --protocol=TCP --silent && exit 0
echo "waiting for mysql"
sleep 2
done
echo "timed out waiting for mysql"
exit 1
- name: Run tests
run: mix test

test-mssql:
name: mssql integration test
runs-on: ubuntu-24.04
env:
MIX_ENV: test
ELIXIR_ASSERT_TIMEOUT: 10000
ECTO_ADAPTER: tds
MSSQL_URL: sa:some!Password@127.0.0.1
strategy:
fail-fast: false
matrix:
elixirbase:
- "1.15.6-erlang-25.3.2.6-alpine-3.18.4"
elixir: ["1.15.6"]
otp: ["25.3.2.6"]
mssql:
- "2019"
- "2022"
services:
mssql:
image: mcr.microsoft.com/mssql/server:${{ matrix.mssql }}-latest
env:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: some!Password
ports:
- 1433:1433
steps:
- uses: earthly/actions-setup@v1
- uses: actions/checkout@v7
- name: test ecto_sql
run: earthly -P --ci --build-arg ELIXIR_BASE=${{matrix.elixirbase}} --build-arg MSSQL=${{matrix.mssql}} +integration-test-mssql
- name: Checkout
uses: actions/checkout@v7
- name: Install Elixir and Erlang
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore deps and _build cache
uses: actions/cache@v6
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-
- name: Install dependencies
run: mix deps.get
- name: Wait for mssql
run: |
for i in $(seq 1 60); do
for sqlcmd in /opt/mssql-tools18/bin/sqlcmd /opt/mssql-tools/bin/sqlcmd; do
if docker exec ${{ job.services.mssql.id }} $sqlcmd -C -S localhost -U sa -P 'some!Password' -Q "SELECT 1" >/dev/null 2>&1; then
exit 0
fi
done
echo "waiting for mssql"
sleep 2
done
echo "timed out waiting for mssql"
exit 1
- name: Run tests
run: mix test
127 changes: 0 additions & 127 deletions Earthfile

This file was deleted.

20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,19 @@ You may also run `mix test.all` to run the unit tests and all integration tests.

$ ECTO_PATH=../ecto mix test.all

### Running containerized tests
### Running databases with Docker

It is also possible to run the integration tests under a containerized environment using [earthly](https://earthly.dev/get-earthly). You will also need Docker installed on your system. Then you can run:
You can also run all databases with Docker:

$ earthly -P +all
$ docker run --name pg -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres:16.2-alpine
$ docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:8.0 --sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES" --default-authentication-plugin=mysql_native_password
$ docker run --name mssql -d -p 1433:1433 -e ACCEPT_EULA=Y -e 'MSSQL_SA_PASSWORD=some!Password' mcr.microsoft.com/mssql/server:2022-latest

You can also use this to interactively debug any failing integration tests using the corresponding commands:
And then point the tests to them:

$ earthly -P -i --build-arg ELIXIR_BASE=1.8.2-erlang-20.3.8.26-alpine-3.11.6 --build-arg MYSQL=5.7 +integration-test-mysql
$ earthly -P -i --build-arg ELIXIR_BASE=1.8.2-erlang-20.3.8.26-alpine-3.11.6 --build-arg MSSQL=2019 +integration-test-mssql
$ earthly -P -i --build-arg ELIXIR_BASE=1.8.2-erlang-20.3.8.26-alpine-3.11.6 --build-arg POSTGRES=11.11 +integration-test-postgres
$ PG_URL=postgres:postgres@127.0.0.1 MYSQL_URL=root:root@127.0.0.1 MSSQL_URL='sa:some!Password@127.0.0.1' mix test.all

Then once you enter the containerized shell, you can inspect the underlying databases with the respective commands:

PGPASSWORD=postgres psql -h 127.0.0.1 -U postgres -d postgres ecto_test
MYSQL_PASSWORD=root mysql -h 127.0.0.1 -uroot -proot ecto_test
sqlcmd -U sa -P 'some!Password'
The `pg` and `myxql` integration tests also require the `pg_dump`/`psql` and `mysqldump`/`mysql` clients, respectively.

## License

Expand Down
Loading