Skip to content

Commit 1c919da

Browse files
committed
Add separate tests for MySQL
Fixes #150.
1 parent 99c3fb2 commit 1c919da

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

.github/workflows/elixir.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ jobs:
4747
--health-interval 10s
4848
--health-timeout 5s
4949
--health-retries 5
50+
mysql:
51+
image: mysql:9
52+
ports: ["3307:3306"]
53+
env:
54+
MYSQL_ROOT_PASSWORD: root
55+
options: >-
56+
--health-cmd "mysqladmin ping --password=root"
57+
--health-interval 10s
58+
--health-timeout 5s
59+
--health-retries 5
5060
name: Elixir v${{ matrix.elixir }}, Erlang v${{ matrix.erlang }}
5161
steps:
5262
- uses: actions/checkout@v4
@@ -96,7 +106,12 @@ jobs:
96106
env:
97107
DB: postgres
98108

99-
- name: Run Tests - MySQL/MariaDB
109+
- name: Run Tests - MariaDB
110+
run: mix test
111+
env:
112+
DB: mariadb
113+
114+
- name: Run Tests - MySQL
100115
run: mix test
101116
env:
102-
DB: mysql
117+
DB: mysql

config/test.example.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ config :error_tracker, ErrorTracker.Test.Repo,
55
pool: Ecto.Adapters.SQL.Sandbox,
66
log: false
77

8+
config :error_tracker, ErrorTracker.Test.MariaDBRepo,
9+
url: "ecto://root:[email protected]:3306/error_tracker_test",
10+
pool: Ecto.Adapters.SQL.Sandbox,
11+
log: false,
12+
# Use the same migrations as the PostgreSQL repo
13+
priv: "priv/repo"
14+
815
config :error_tracker, ErrorTracker.Test.MySQLRepo,
9-
url: "ecto://root:[email protected]/error_tracker_test",
16+
url: "ecto://root:[email protected]:3307/error_tracker_test",
1017
pool: Ecto.Adapters.SQL.Sandbox,
1118
log: false,
1219
# Use the same migrations as the PostgreSQL repo
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule ErrorTracker.StoreFetchTest do
2+
@moduledoc """
3+
Test if simple store-retrieve operations are successful.
4+
5+
This is necessary, because some Ecto adapters like `Ecto.Adapters.MyXQL` may successfully store a field, but crash on retrieval.
6+
"""
7+
use ErrorTracker.Test.Case
8+
9+
test "after reporting an error its occurrence should be retrievable from DB" do
10+
assert %ErrorTracker.Occurrence{id: occurrence_id} =
11+
report_error(fn -> raise "BOOM" end)
12+
13+
assert %ErrorTracker.Occurrence{} = repo().get!(ErrorTracker.Occurrence, occurrence_id)
14+
end
15+
end

test/support/mariadb_repo.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defmodule ErrorTracker.Test.MariaDBRepo do
2+
@moduledoc false
3+
use Ecto.Repo, otp_app: :error_tracker, adapter: Ecto.Adapters.MyXQL
4+
end

test/test_helper.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ repo =
77
"mysql" ->
88
ErrorTracker.Test.MySQLRepo
99

10+
"mariadb" ->
11+
ErrorTracker.Test.MariaDBRepo
12+
1013
"postgres" ->
1114
ErrorTracker.Test.Repo
1215

1316
_other ->
14-
raise "Please run either `DB=sqlite mix test`, `DB=postgres mix test` or `DB=mysql mix test`"
17+
raise "Please run either `DB=sqlite mix test`, `DB=postgres mix test`, `DB=mariadb mix test` or `DB=mysql mix test`"
1518
end
1619

1720
Application.put_env(:error_tracker, :repo, repo)

0 commit comments

Comments
 (0)