Skip to content

Commit 0dcf5ff

Browse files
committed
fix a lot of test warnings
1 parent 45f83d6 commit 0dcf5ff

File tree

9 files changed

+119
-142
lines changed

9 files changed

+119
-142
lines changed

test/client_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ defmodule Sentry.ClientTest do
9090
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
9191

9292
try do
93-
Event.not_a_function()
93+
apply(Event, :not_a_function, [])
9494
rescue
9595
e ->
9696
assert capture_log(fn ->
@@ -134,7 +134,7 @@ defmodule Sentry.ClientTest do
134134
Logger.metadata(key: "value", user_id: 1)
135135

136136
try do
137-
Event.not_a_function()
137+
apply(Event, :not_a_function, [])
138138
rescue
139139
e ->
140140
assert capture_log(fn ->
@@ -163,7 +163,7 @@ defmodule Sentry.ClientTest do
163163
Logger.metadata(key: "value", user_id: 1)
164164

165165
try do
166-
Event.not_a_function()
166+
apply(Event, :not_a_function, [])
167167
rescue
168168
e ->
169169
assert capture_log(fn ->
@@ -207,7 +207,7 @@ defmodule Sentry.ClientTest do
207207
)
208208

209209
try do
210-
Event.not_a_function()
210+
apply(Event, :not_a_function, [])
211211
rescue
212212
e ->
213213
assert capture_log(fn ->
@@ -234,7 +234,7 @@ defmodule Sentry.ClientTest do
234234
)
235235

236236
try do
237-
Event.not_a_function()
237+
apply(Event, :not_a_function, [])
238238
rescue
239239
e ->
240240
assert capture_log(fn ->
@@ -261,7 +261,7 @@ defmodule Sentry.ClientTest do
261261
)
262262

263263
try do
264-
Event.not_a_function()
264+
apply(Event, :not_a_function, [])
265265
rescue
266266
e ->
267267
{:ok, _} =
@@ -289,7 +289,7 @@ defmodule Sentry.ClientTest do
289289
)
290290

291291
try do
292-
Event.not_a_function()
292+
apply(Event, :not_a_function, [])
293293
rescue
294294
e ->
295295
{:ok, _} = Sentry.capture_exception(e, result: :sync, sample_rate: 1)
@@ -328,7 +328,7 @@ defmodule Sentry.ClientTest do
328328

329329
capture_log(fn ->
330330
try do
331-
Event.not_a_function()
331+
apply(Event, :not_a_function, [])
332332
rescue
333333
e ->
334334
{:ok, task} =

test/event_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Sentry.EventTest do
55

66
def event_generated_by_exception(extra \\ %{}) do
77
try do
8-
Event.not_a_function(1, 2, 3)
8+
apply(Event, :not_a_function, [1, 2, 3])
99
rescue
1010
e -> Event.transform_exception(e, stacktrace: __STACKTRACE__, extra: extra)
1111
end

test/logger_backend_test.exs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ defmodule Sentry.LoggerBackendTest do
134134
{:ok, body, conn} = Plug.Conn.read_body(conn)
135135
json = Jason.decode!(body)
136136
assert length(json["stacktrace"]["frames"]) == 1
137-
assert List.first(json["stacktrace"]["frames"])["filename"] == "test/support/test_plug.ex"
137+
138+
assert List.first(json["stacktrace"]["frames"])["filename"] ==
139+
"test/support/test_plug_applications.ex"
140+
138141
send(pid, "API called")
139142
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
140143
end)
@@ -143,7 +146,7 @@ defmodule Sentry.LoggerBackendTest do
143146

144147
capture_log(fn ->
145148
Plug.Test.conn(:get, "/spawn_error_route")
146-
|> Sentry.ExampleApp.call([])
149+
|> Sentry.TestPlugApplications.Example.call([])
147150

148151
assert_receive "API called"
149152
end)
@@ -184,22 +187,11 @@ defmodule Sentry.LoggerBackendTest do
184187
end
185188

186189
test "only sends one error when a Plug process crashes" do
187-
Code.compile_string("""
188-
defmodule SentryApp do
189-
use Plug.Router
190-
use Plug.ErrorHandler
191-
use Sentry.Plug
192-
plug :match
193-
plug :dispatch
194-
forward("/", to: Sentry.ExampleApp)
195-
end
196-
""")
197-
198190
bypass = Bypass.open()
199191
pid = self()
200192
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
201193

202-
{:ok, _plug_pid} = Plug.Cowboy.http(SentryApp, [], port: 8003)
194+
{:ok, _plug_pid} = Plug.Cowboy.http(Sentry.TestPlugApplications.DefaultConfig, [], port: 8003)
203195

204196
Bypass.expect(bypass, fn conn ->
205197
{:ok, body, conn} = Plug.Conn.read_body(conn)

test/phoenix_endpoint_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule Sentry.PhoenixEndpointTest do
1313
use Phoenix.Endpoint, otp_app: :sentry
1414
use Sentry.Phoenix.Endpoint
1515
plug(:error)
16-
plug(Sentry.ExampleApp)
16+
plug(Sentry.TestPlugApplications.Example)
1717

1818
def error(_conn, _opts) do
1919
raise "EndpointError"

test/plug_test.exs

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,27 @@ defmodule Sentry.PlugTest do
22
use ExUnit.Case
33
use Plug.Test
44
import Sentry.TestEnvironmentHelper
5+
alias Sentry.TestPlugApplications
56

67
test "non-existent route exceptions are ignored" do
7-
exception = %FunctionClauseError{arity: 4, function: :do_match, module: Sentry.ExampleApp}
8+
exception = %FunctionClauseError{
9+
arity: 4,
10+
function: :do_match,
11+
module: TestPlugApplications.Example
12+
}
813

914
assert ^exception =
1015
assert_raise(
1116
FunctionClauseError,
12-
"no function clause matching in Sentry.ExampleApp.do_match/4",
17+
"no function clause matching in Sentry.TestPlugApplications.Example.do_match/4",
1318
fn ->
1419
conn(:get, "/not_found")
15-
|> Sentry.ExampleApp.call([])
20+
|> TestPlugApplications.Example.call([])
1621
end
1722
)
1823
end
1924

2025
test "overriding handle_errors/2" do
21-
Code.compile_string("""
22-
defmodule OverrideApp do
23-
use Plug.Router
24-
use Plug.ErrorHandler
25-
use Sentry.Plug
26-
plug :match
27-
plug :dispatch
28-
forward("/", to: Sentry.ExampleApp)
29-
30-
defp handle_errors(conn, %{kind: _kind, reason: _reason, stack: _stack} = error) do
31-
super(conn, error)
32-
send_resp(conn, conn.status, "Something went terribly wrong")
33-
end
34-
end
35-
""")
36-
3726
bypass = Bypass.open()
3827

3928
Bypass.expect(bypass, fn conn ->
@@ -45,24 +34,13 @@ defmodule Sentry.PlugTest do
4534
conn = conn(:post, "/error_route", %{})
4635

4736
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
48-
OverrideApp.call(conn, [])
37+
TestPlugApplications.Override.call(conn, [])
4938
end)
5039

5140
assert {500, _headers, "Something went terribly wrong"} = sent_resp(conn)
5241
end
5342

5443
test "default data scrubbing" do
55-
Code.compile_string("""
56-
defmodule DefaultConfigApp do
57-
use Plug.Router
58-
use Plug.ErrorHandler
59-
use Sentry.Plug
60-
plug :match
61-
plug :dispatch
62-
forward("/", to: Sentry.ExampleApp)
63-
end
64-
""")
65-
6644
bypass = Bypass.open()
6745

6846
Bypass.expect(bypass, fn conn ->
@@ -91,22 +69,11 @@ defmodule Sentry.PlugTest do
9169
|> put_req_header("authorization", "secrets")
9270
|> put_req_header("authentication", "secrets")
9371
|> put_req_header("content-type", "application/json")
94-
|> DefaultConfigApp.call([])
72+
|> TestPlugApplications.DefaultConfig.call([])
9573
end)
9674
end
9775

9876
test "handles data scrubbing with file upload" do
99-
Code.compile_string("""
100-
defmodule ScrubbingWithFileApp do
101-
use Plug.Router
102-
use Plug.ErrorHandler
103-
use Sentry.Plug
104-
plug :match
105-
plug :dispatch
106-
forward("/", to: Sentry.ExampleApp)
107-
end
108-
""")
109-
11077
bypass = Bypass.open()
11178

11279
Bypass.expect(bypass, fn conn ->
@@ -125,24 +92,11 @@ defmodule Sentry.PlugTest do
12592
|> put_req_cookie("cookie_key", "cookie_value")
12693
|> put_req_header("accept-language", "en-US")
12794
|> put_req_header("authorization", "ignorme")
128-
|> ScrubbingWithFileApp.call([])
95+
|> TestPlugApplications.ScrubbingWithFile.call([])
12996
end)
13097
end
13198

13299
test "custom cookie scrubbing" do
133-
Code.compile_string("""
134-
defmodule CustomCookieScrubberApp do
135-
use Plug.Router
136-
use Plug.ErrorHandler
137-
use Sentry.Plug, cookie_scrubber: fn(conn) ->
138-
Map.take(conn.req_cookies, ["regular"])
139-
end
140-
plug :match
141-
plug :dispatch
142-
forward("/", to: Sentry.ExampleApp)
143-
end
144-
""")
145-
146100
bypass = Bypass.open()
147101

148102
Bypass.expect(bypass, fn conn ->
@@ -158,22 +112,11 @@ defmodule Sentry.PlugTest do
158112
conn(:get, "/error_route")
159113
|> update_req_cookie("secret", "secretvalue")
160114
|> update_req_cookie("regular", "value")
161-
|> CustomCookieScrubberApp.call([])
115+
|> TestPlugApplications.CustomCookieScrubber.call([])
162116
end)
163117
end
164118

165119
test "collects feedback" do
166-
Code.compile_string("""
167-
defmodule CollectFeedbackApp do
168-
use Plug.Router
169-
use Plug.ErrorHandler
170-
use Sentry.Plug, collect_feedback: [enabled: true, options: %{title: "abc-123"}]
171-
plug :match
172-
plug :dispatch
173-
forward("/", to: Sentry.ExampleApp)
174-
end
175-
""")
176-
177120
bypass = Bypass.open()
178121

179122
Bypass.expect(bypass, fn conn ->
@@ -188,7 +131,7 @@ defmodule Sentry.PlugTest do
188131
|> Plug.Conn.put_req_header("accept", "text/html")
189132

190133
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
191-
CollectFeedbackApp.call(conn, [])
134+
TestPlugApplications.CollectFeedback.call(conn, [])
192135
end)
193136

194137
assert_received {:plug_conn, :sent}

test/sources_test.exs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,10 @@ defmodule Sentry.SourcesTest do
44
import Sentry.TestEnvironmentHelper
55

66
test "exception makes call to Sentry API" do
7-
Code.compile_string("""
8-
defmodule SourcesApp do
9-
use Plug.Router
10-
use Plug.ErrorHandler
11-
use Sentry.Plug
12-
13-
plug :match
14-
plug :dispatch
15-
forward("/", to: Sentry.ExampleApp)
16-
end
17-
""")
18-
197
correct_context = %{
20-
"context_line" => " raise RuntimeError, \"Error\"",
21-
"post_context" => [" end", "", " post \"/error_route\" do"],
22-
"pre_context" => ["", " get \"/error_route\" do", " _ = conn"]
8+
"context_line" => " raise RuntimeError, \"Error\"",
9+
"post_context" => [" end", "", " post \"/error_route\" do"],
10+
"pre_context" => ["", " get \"/error_route\" do", " _ = conn"]
2311
}
2412

2513
bypass = Bypass.open()
@@ -37,7 +25,7 @@ defmodule Sentry.SourcesTest do
3725
|> Map.take(["context_line", "post_context", "pre_context"])
3826

3927
assert body =~ "RuntimeError"
40-
assert body =~ "ExampleApp"
28+
assert body =~ "DefaultConfig"
4129
assert conn.request_path == "/api/1/store/"
4230
assert conn.method == "POST"
4331
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
@@ -47,7 +35,7 @@ defmodule Sentry.SourcesTest do
4735

4836
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
4937
conn(:get, "/error_route")
50-
|> SourcesApp.call([])
38+
|> Sentry.TestPlugApplications.DefaultConfig.call([])
5139
end)
5240
end
5341
end

test/support/test_plug.ex

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)