forked from getsentry/sentry-elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsources_test.exs
53 lines (43 loc) · 1.42 KB
/
sources_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
defmodule Sentry.SourcesTest do
use ExUnit.Case
use Plug.Test
import Sentry.TestEnvironmentHelper
test "exception makes call to Sentry API" do
Code.compile_string("""
defmodule SourcesApp do
use Plug.Router
use Plug.ErrorHandler
use Sentry.Plug
plug :match
plug :dispatch
forward("/", to: Sentry.ExampleApp)
end
""")
correct_context = %{
"context_line" => " raise RuntimeError, \"Error\"",
"post_context" => [" end", "", " post \"/error_route\" do"],
"pre_context" => ["", " get \"/error_route\" do", " _ = conn"]
}
bypass = Bypass.open()
Bypass.expect(bypass, fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)
frames =
Jason.decode!(body)
|> get_in(["stacktrace", "frames"])
|> Enum.reverse()
assert ^correct_context =
Enum.at(frames, 0)
|> Map.take(["context_line", "post_context", "pre_context"])
assert body =~ "RuntimeError"
assert body =~ "ExampleApp"
assert conn.request_path == "/api/1/store/"
assert conn.method == "POST"
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
end)
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
conn(:get, "/error_route")
|> SourcesApp.call([])
end)
end
end