Skip to content

Commit 100e4b9

Browse files
committed
Test Sentry call correctly
1 parent 79a65ff commit 100e4b9

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ config :sentry,
8282
included_environments: ~w(prod staging)a,
8383
use_error_logger: true
8484

85+
config :code_corps, :sentry, CodeCorps.Sentry.Async
86+
8587
config :code_corps, :processor, CodeCorps.Processor.Async
8688

8789
# Import environment specific config. This must remain at the bottom

config/test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ config :code_corps,
5757
config :sentry,
5858
environment_name: Mix.env || :test
5959

60+
config :code_corps, :sentry, CodeCorps.Sentry.Sync
61+
6062
config :code_corps, :processor, CodeCorps.Processor.Sync
6163

6264
config :code_corps, CodeCorps.Mailer,

lib/code_corps/github/event.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule CodeCorps.GitHub.Event do
4545
end
4646
def stop_processing({:error, reason, error}, %GithubEvent{} = event) do
4747
%GitHubEventError{reason: error}
48-
|> Sentry.capture_exception([stacktrace: System.stacktrace()])
48+
|> CodeCorps.Sentry.capture_exception([stacktrace: System.stacktrace()])
4949

5050
changes = %{
5151
status: "errored",

lib/code_corps/sentry/async.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule CodeCorps.Sentry.Async do
2+
def capture_exception(exception, opts \\ []) do
3+
exception
4+
|> Sentry.capture_exception(opts)
5+
end
6+
end

lib/code_corps/sentry/sentry.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule CodeCorps.Sentry do
2+
@sentry Application.get_env(:code_corps, :sentry)
3+
4+
def capture_exception(exception, opts \\ []) do
5+
@sentry.capture_exception(exception, opts)
6+
end
7+
end

lib/code_corps/sentry/sync.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule CodeCorps.Sentry.Sync do
2+
def capture_exception(exception, opts \\ []) do
3+
exception
4+
|> Sentry.capture_exception(opts |> Keyword.put(:result, :sync))
5+
end
6+
end

test/lib/code_corps/github/webhook/handler_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ defmodule CodeCorps.GitHub.Webhook.HandlerTest do
264264
bypass = Bypass.open
265265
Bypass.expect bypass, fn conn ->
266266
{:ok, body, conn} = Plug.Conn.read_body(conn)
267-
assert body =~ "RuntimeError"
268-
assert body =~ "ExampleApp"
267+
assert body =~ "GitHubEventError"
268+
assert body =~ "CodeCorps"
269269
assert conn.request_path == "/api/1/store/"
270270
assert conn.method == "POST"
271271
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
272272
end
273273

274+
modify_env(:sentry, environment_name: :prod)
274275
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
275276

276277
{:ok, %GithubEvent{} = event} = Handler.handle_supported("issues", "abc-456", edited_payload)

0 commit comments

Comments
 (0)