diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 78fbea3..d4473cc 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -47,6 +47,16 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + mysql: + image: mysql:9 + ports: ["3307:3306"] + env: + MYSQL_ROOT_PASSWORD: root + options: >- + --health-cmd "mysqladmin ping --password=root" + --health-interval 10s + --health-timeout 5s + --health-retries 5 name: Elixir v${{ matrix.elixir }}, Erlang v${{ matrix.erlang }} steps: - uses: actions/checkout@v4 @@ -96,7 +106,12 @@ jobs: env: DB: postgres - - name: Run Tests - MySQL/MariaDB + - name: Run Tests - MariaDB + run: mix test + env: + DB: mariadb + + - name: Run Tests - MySQL run: mix test env: - DB: mysql + DB: mysql \ No newline at end of file diff --git a/config/test.example.exs b/config/test.example.exs index 5ebac14..64f58c9 100644 --- a/config/test.example.exs +++ b/config/test.example.exs @@ -5,8 +5,15 @@ config :error_tracker, ErrorTracker.Test.Repo, pool: Ecto.Adapters.SQL.Sandbox, log: false +config :error_tracker, ErrorTracker.Test.MariaDBRepo, + url: "ecto://root:root@127.0.0.1:3306/error_tracker_test", + pool: Ecto.Adapters.SQL.Sandbox, + log: false, + # Use the same migrations as the PostgreSQL repo + priv: "priv/repo" + config :error_tracker, ErrorTracker.Test.MySQLRepo, - url: "ecto://root:root@127.0.0.1/error_tracker_test", + url: "ecto://root:root@127.0.0.1:3307/error_tracker_test", pool: Ecto.Adapters.SQL.Sandbox, log: false, # Use the same migrations as the PostgreSQL repo diff --git a/test/error_tracker/store_fetch_test.exs b/test/error_tracker/store_fetch_test.exs new file mode 100644 index 0000000..abfcd9b --- /dev/null +++ b/test/error_tracker/store_fetch_test.exs @@ -0,0 +1,15 @@ +defmodule ErrorTracker.StoreFetchTest do + @moduledoc """ + Test if simple store-retrieve operations are successful. + + This is necessary, because some Ecto adapters like `Ecto.Adapters.MyXQL` may successfully store a field, but crash on retrieval. + """ + use ErrorTracker.Test.Case + + test "after reporting an error its occurrence should be retrievable from DB" do + assert %ErrorTracker.Occurrence{id: occurrence_id} = + report_error(fn -> raise "BOOM" end) + + assert %ErrorTracker.Occurrence{} = repo().get!(ErrorTracker.Occurrence, occurrence_id) + end +end diff --git a/test/support/mariadb_repo.ex b/test/support/mariadb_repo.ex new file mode 100644 index 0000000..3c76a49 --- /dev/null +++ b/test/support/mariadb_repo.ex @@ -0,0 +1,4 @@ +defmodule ErrorTracker.Test.MariaDBRepo do + @moduledoc false + use Ecto.Repo, otp_app: :error_tracker, adapter: Ecto.Adapters.MyXQL +end diff --git a/test/test_helper.exs b/test/test_helper.exs index 4079193..d549dd3 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -7,11 +7,14 @@ repo = "mysql" -> ErrorTracker.Test.MySQLRepo + "mariadb" -> + ErrorTracker.Test.MariaDBRepo + "postgres" -> ErrorTracker.Test.Repo _other -> - raise "Please run either `DB=sqlite mix test`, `DB=postgres mix test` or `DB=mysql mix test`" + raise "Please run either `DB=sqlite mix test`, `DB=postgres mix test`, `DB=mariadb mix test` or `DB=mysql mix test`" end Application.put_env(:error_tracker, :repo, repo)