Skip to content

Commit

Permalink
test: Honeybadger.Notice.from_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jun 13, 2024
1 parent c3c5fa0 commit bccb164
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/tower_honeybadger/honeybadger/notice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ defmodule TowerHoneybadger.Honeybadger.Notice do
|> Map.put("request", request_data(conn))
end

defp maybe_put_request_data(notice, _) do
notice
end

defp request_data(%Plug.Conn{} = conn) do
conn =
conn
Expand All @@ -60,6 +64,6 @@ defmodule TowerHoneybadger.Honeybadger.Notice do
end

defp environment do
Application.fetch_env!(:tower_honeybadge, :environment)
Application.fetch_env!(:tower_honeybadger, :environment)
end
end
71 changes: 71 additions & 0 deletions test/tower_honeybadger/honeybadger/notice_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
defmodule TowerHoneybadger.Honeybadger.NoticeTest do
use ExUnit.Case
doctest TowerHoneybadger.Honeybadger.Notice

alias TowerHoneybadger.Honeybadger

test "from_exception" do
Application.put_env(:tower_honeybadger, :environment, "test")

notice =
try do
raise "a test"
rescue
exception in RuntimeError ->
Honeybadger.Notice.from_exception(exception, __STACKTRACE__)
end

assert %{
"error" => %{
"class" => "RuntimeError",
"message" => "a test",
"backtrace" => [
%{
"method" =>
~s(TowerHoneybadger.Honeybadger.NoticeTest."test from_exception"/1),
"file" => "test/tower_honeybadger/honeybadger/notice_test.exs",
"number" => 12
},
%{
"method" => _,
"file" => "lib/ex_unit/runner.ex",
"number" => _
},
%{
"method" => _,
"file" => "timer.erl",
"number" => _
},
%{
"method" => _,
"file" => "lib/ex_unit/runner.ex",
"number" => _
}
]
},
"server" => %{
"environment_name" => "test"
}
} = notice
end

#
# test "from_message" do
# Application.put_env(:tower_honeybadger, :environment, "test")
#
# notice = Honeybadger.Notice.from_message("something interesting happened")
#
# assert %{
# "data" => %{
# "environment" => "test",
# "timestamp" => _,
# "level" => "info",
# "body" => %{
# "message" => %{
# "body" => "something interesting happened"
# }
# }
# }
# } = notice
# end
end

0 comments on commit bccb164

Please sign in to comment.