11defmodule Sentry.ClientTest do
2- use ExUnit.Case , async: true
2+ use ExUnit.Case
3+ import ExUnit.CaptureLog
4+
35 alias Sentry.Client
46 @ sentry_dsn "https://public:[email protected] /1" 57
@@ -8,11 +10,33 @@ defmodule Sentry.ClientTest do
810 assert Client . authorization_header ( public_key , private_key ) =~ ~r/ Sentry sentry_version=5, sentry_client=sentry-elixir\/ #{ Application . spec ( :sentry , :vsn ) } , sentry_timestamp=\d {10}, sentry_key=public, sentry_secret=secret/
911 end
1012
11- test "parning dsn" do
13+ test "parsing dsn" do
1214 assert { "https://app.getsentry.com:443/api/1/store/" , "public" , "secret" } =
1315 Sentry.Client . parse_dsn! ( "https://public:[email protected] /1" ) 1416
1517 assert { "http://app.getsentry.com:9000/api/1/store/" , "public" , "secret" } =
1618 Sentry.Client . parse_dsn! ( "http://public:[email protected] :9000/1" ) 1719 end
20+
21+ test "logs api errors" do
22+ bypass = Bypass . open
23+ Bypass . expect bypass , fn conn ->
24+ { :ok , _body , conn } = Plug.Conn . read_body ( conn )
25+ assert conn . request_path == "/api/1/store/"
26+ assert conn . method == "POST"
27+ Plug.Conn . put_resp_header ( conn , "X-Sentry-Error" , "Creation of this event was denied due to rate limiting." )
28+ |> Plug.Conn . resp ( 400 , "Something bad happened" )
29+ end
30+
31+ Application . put_env ( :sentry , :dsn , "http://public:secret@localhost:#{ bypass . port } /1" )
32+
33+ try do
34+ Event . not_a_function
35+ rescue
36+ e ->
37+ assert capture_log ( fn ->
38+ Sentry . capture_exception ( e )
39+ end ) =~ ~r/ 400.*Creation of this event was denied due to rate limiting/
40+ end
41+ end
1842end
0 commit comments