-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unit tests for: - `ErrorTracker`. - `report/3` - with a runtime exception - with a bad arithmetic error - with an unknown function error - with a throw - with an exit - `resolve/1` - `unresolve/1` - `Telemetry` - verifies that events are emitted Tests can run either on PostgreSQL or SQLite3. This is determined by the `DB` env var so: - `DB=postgres mix test` runs the tests on PostgreSQL - `DB=sqlite mix test` runs the tests on SQLite3 The CI has been also updated to run tests on both databases. --- I've also unified the configuration under the `config/` folder. And the dev/test migrations under `priv/repo/`. Previously we had some configuration in the root folder and other in `config/`. Regarding the migrations the `priv/repo/` folder is not included when publishing the package but is used in dev/test.
- Loading branch information
Showing
22 changed files
with
345 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,3 @@ | ||
import Config | ||
|
||
if config_env() == :dev do | ||
config :tailwind, | ||
version: "3.4.3", | ||
default: [ | ||
args: ~w( | ||
--config=tailwind.config.js | ||
--input=css/app.css | ||
--output=../priv/static/app.css | ||
), | ||
cd: Path.expand("../assets", __DIR__) | ||
] | ||
|
||
config :bun, | ||
version: "1.1.18", | ||
default: [ | ||
args: ~w(build app.js --outdir=../../priv/static), | ||
cd: Path.expand("../assets/js", __DIR__), | ||
env: %{} | ||
] | ||
end | ||
import_config "#{config_env()}.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Config | ||
|
||
config :tailwind, | ||
version: "3.4.3", | ||
default: [ | ||
args: ~w( | ||
--config=tailwind.config.js | ||
--input=css/app.css | ||
--output=../priv/static/app.css | ||
), | ||
cd: Path.expand("../assets", __DIR__) | ||
] | ||
|
||
config :bun, | ||
version: "1.1.18", | ||
default: [ | ||
args: ~w(build app.js --outdir=../../priv/static), | ||
cd: Path.expand("../assets/js", __DIR__), | ||
env: %{} | ||
] | ||
|
||
# PostgreSQL adapter | ||
# | ||
# To use SQLite3 on your local development machine uncomment these lines and | ||
# comment the lines of other adapters. | ||
|
||
config :error_tracker, :ecto_adapter, :postgres | ||
|
||
config :error_tracker, ErrorTrackerDev.Repo, | ||
url: "ecto://postgres:[email protected]/error_tracker_dev" | ||
|
||
# SQLite3 adapter | ||
# | ||
# To use SQLite3 on your local development machine uncomment these lines and | ||
# comment the lines of other adapters. | ||
|
||
# config :error_tracker, :ecto_adapter, :sqlite3 | ||
|
||
# config :error_tracker, ErrorTrackerDev.Repo, | ||
# database: System.get_env("SQLITE_DB") || "dev.db" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Config | ||
|
||
config :error_tracker, ErrorTracker.Test.Repo, | ||
url: "ecto://postgres:[email protected]/error_tracker_test", | ||
pool: Ecto.Adapters.SQL.Sandbox, | ||
log: false | ||
|
||
config :error_tracker, ErrorTracker.Test.LiteRepo, | ||
database: "priv/lite_repo/test.db", | ||
pool: Ecto.Adapters.SQL.Sandbox, | ||
log: false, | ||
# Use the same migrations as the PostgreSQL repo | ||
priv: "priv/repo" | ||
|
||
config :error_tracker, ecto_repos: [ErrorTracker.Test.Repo] | ||
|
||
# Repo is selected in the test_helper.exs based on the given ENV vars | ||
config :error_tracker, otp_app: :error_tracker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
priv/repo/migrations/20240527155639_create_error_tracker_tables.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule ErrorTracker.Repo.Migrations.CreateErrorTrackerTables do | ||
use Ecto.Migration | ||
|
||
defdelegate up, to: ErrorTracker.Migration | ||
defdelegate down, to: ErrorTracker.Migration | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule ErrorTracker.TelemetryTest do | ||
use ErrorTracker.Test.Case | ||
|
||
alias ErrorTracker.Error | ||
alias ErrorTracker.Occurrence | ||
|
||
setup do | ||
attach_telemetry() | ||
|
||
:ok | ||
end | ||
|
||
test "event is emitted for new errors" do | ||
# Since the error is new, both the new error and new occurrence events will be emitted | ||
report_error(fn -> raise "This is a test" end) | ||
assert_receive {:telemetry_event, [:error_tracker, :error, :new], _, %{error: %Error{}}} | ||
|
||
assert_receive {:telemetry_event, [:error_tracker, :occurrence, :new], _, | ||
%{occurrence: %Occurrence{}}} | ||
|
||
# The error is already known so the new error event won't be emitted | ||
report_error(fn -> raise "This is a test" end) | ||
|
||
refute_receive {:telemetry_event, [:error_tracker, :error, :new], _, | ||
%{occurrence: %Occurrence{}}}, | ||
150 | ||
|
||
assert_receive {:telemetry_event, [:error_tracker, :occurrence, :new], _, | ||
%{occurrence: %Occurrence{}}} | ||
end | ||
|
||
test "event is emitted for resolved and unresolved errors" do | ||
%Occurrence{error: error = %Error{}} = report_error(fn -> raise "This is a test" end) | ||
|
||
# The resolved event will be emitted | ||
{:ok, resolved = %Error{}} = ErrorTracker.resolve(error) | ||
assert_receive {:telemetry_event, [:error_tracker, :error, :resolved], _, %{error: %Error{}}} | ||
|
||
# The unresolved event will be emitted | ||
{:ok, _unresolved} = ErrorTracker.unresolve(resolved) | ||
|
||
assert_receive {:telemetry_event, [:error_tracker, :error, :unresolved], _, | ||
%{error: %Error{}}} | ||
end | ||
end |
Oops, something went wrong.