Skip to content

Commit b427704

Browse files
committed
Simplify test helpers
1 parent fa8b499 commit b427704

15 files changed

+139
-175
lines changed

test/context_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Sentry.ContextTest do
22
use ExUnit.Case, async: false
33

4-
import Sentry.TestEnvironmentHelper
4+
import Sentry.TestHelpers
55

66
alias Sentry.{Context, Event, Interfaces}
77

@@ -80,7 +80,7 @@ defmodule Sentry.ContextTest do
8080
@tag start_app: false
8181
test "passing in tags context as option overrides Context and Application config" do
8282
Context.set_tags_context(%{"key" => "345", "key1" => "123"})
83-
modify_env(:sentry, tags: %{"key" => "overridden", "key2" => "1234", "key3" => "12345"})
83+
modify_app_env(tags: %{"key" => "overridden", "key2" => "1234", "key3" => "12345"})
8484

8585
event = Event.create_event(tags: %{"key" => "123"})
8686

test/envelope_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
defmodule Sentry.EnvelopeTest do
22
use ExUnit.Case, async: false
33

4+
import Sentry.TestHelpers
5+
46
alias Sentry.{Envelope, Event, Interfaces}
5-
alias Sentry.TestEnvironmentHelper
67

78
describe "from_binary/1" do
89
test "parses envelope with empty headers" do
@@ -133,7 +134,7 @@ defmodule Sentry.EnvelopeTest do
133134

134135
describe "to_binary/1" do
135136
test "encodes an envelope" do
136-
TestEnvironmentHelper.modify_env(:sentry, environment_name: "test")
137+
modify_app_env(environment_name: "test")
137138

138139
event = Event.create_event([])
139140
envelope = Envelope.new([event])

test/event_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
defmodule Sentry.EventTest do
22
use ExUnit.Case, async: false
33

4+
import Sentry.TestHelpers
5+
46
alias Sentry.Event
57
alias Sentry.Interfaces
68

7-
import Sentry.TestEnvironmentHelper
8-
99
doctest Event, import: true
1010

1111
def event_generated_by_exception(extra \\ %{}) do
@@ -290,7 +290,7 @@ defmodule Sentry.EventTest do
290290
end
291291

292292
test "sets :in_app to true when configured" do
293-
modify_env(:sentry, in_app_module_allow_list: [Sentry, :random, Sentry.Submodule])
293+
modify_app_env(in_app_module_allow_list: [Sentry, :random, Sentry.Submodule])
294294
exception = RuntimeError.exception("error")
295295

296296
event =

test/logger_backend_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
defmodule Sentry.LoggerBackendTest do
22
use ExUnit.Case, async: false
33

4-
alias Sentry.TestEnvironmentHelper
4+
import Sentry.TestHelpers
5+
56
alias Sentry.TestGenServer
67

78
require Logger
@@ -338,7 +339,7 @@ defmodule Sentry.LoggerBackendTest do
338339
pid = self()
339340
ref = make_ref()
340341

341-
TestEnvironmentHelper.modify_env(:sentry,
342+
modify_app_env(
342343
before_send: fn event ->
343344
send(pid, {ref, event})
344345
false

test/mix/sentry.send_test_event_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
22
use ExUnit.Case
33

44
import ExUnit.CaptureIO
5-
import Sentry.TestEnvironmentHelper
5+
import Sentry.TestHelpers
66

77
test "prints if :dsn is not set" do
8-
modify_env(:sentry, dsn: nil)
8+
modify_app_env(dsn: nil)
99

1010
output =
1111
capture_io(fn ->
@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
3232
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
3333
end)
3434

35-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
35+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
3636

3737
output =
3838
capture_io(fn ->
@@ -62,7 +62,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
6262
Plug.Conn.resp(conn, 500, ~s<{"id": "340"}>)
6363
end)
6464

65-
modify_env(:sentry,
65+
modify_app_env(
6666
dsn: "http://public:secret@localhost:#{bypass.port}/1",
6767
request_retries: []
6868
)

test/plug_capture_test.exs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Sentry.PlugCaptureTest do
22
use ExUnit.Case
33
use Plug.Test
44

5-
import Sentry.TestEnvironmentHelper
5+
import Sentry.TestHelpers
66
import ExUnit.CaptureLog
77

88
defmodule PhoenixController do
@@ -56,12 +56,12 @@ defmodule Sentry.PlugCaptureTest do
5656
Bypass.expect(bypass, fn conn ->
5757
{:ok, body, conn} = Plug.Conn.read_body(conn)
5858

59-
_event = TestHelpers.decode_event_from_envelope!(body)
59+
_event = decode_event_from_envelope!(body)
6060

6161
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
6262
end)
6363

64-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
64+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
6565

6666
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
6767
conn(:get, "/error_route")
@@ -75,12 +75,12 @@ defmodule Sentry.PlugCaptureTest do
7575
Bypass.expect(bypass, fn conn ->
7676
{:ok, body, conn} = Plug.Conn.read_body(conn)
7777

78-
_event = TestHelpers.decode_event_from_envelope!(body)
78+
_event = decode_event_from_envelope!(body)
7979

8080
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
8181
end)
8282

83-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
83+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
8484

8585
catch_throw(
8686
conn(:get, "/throw_route")
@@ -94,12 +94,12 @@ defmodule Sentry.PlugCaptureTest do
9494
Bypass.expect(bypass, fn conn ->
9595
{:ok, body, conn} = Plug.Conn.read_body(conn)
9696

97-
_event = TestHelpers.decode_event_from_envelope!(body)
97+
_event = decode_event_from_envelope!(body)
9898

9999
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
100100
end)
101101

102-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
102+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
103103

104104
catch_exit(
105105
conn(:get, "/exit_route")
@@ -113,7 +113,7 @@ defmodule Sentry.PlugCaptureTest do
113113
Bypass.expect(bypass, fn conn ->
114114
{:ok, body, conn} = Plug.Conn.read_body(conn)
115115

116-
event = TestHelpers.decode_event_from_envelope!(body)
116+
event = decode_event_from_envelope!(body)
117117

118118
assert event.request["url"] == "http://www.example.com/error_route"
119119
assert event.request["method"] == "GET"
@@ -122,7 +122,7 @@ defmodule Sentry.PlugCaptureTest do
122122
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
123123
end)
124124

125-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
125+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
126126

127127
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
128128
conn(:get, "/error_route")
@@ -136,12 +136,12 @@ defmodule Sentry.PlugCaptureTest do
136136
Bypass.expect_once(bypass, fn conn ->
137137
{:ok, body, conn} = Plug.Conn.read_body(conn)
138138

139-
_event = TestHelpers.decode_event_from_envelope!(body)
139+
_event = decode_event_from_envelope!(body)
140140

141141
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
142142
end)
143143

144-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
144+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
145145

146146
assert_raise(Plug.Conn.WrapperError, "** (RuntimeError) Error", fn ->
147147
conn(:get, "/error_route")
@@ -165,7 +165,7 @@ defmodule Sentry.PlugCaptureTest do
165165
Bypass.expect(bypass, fn conn ->
166166
{:ok, body, conn} = Plug.Conn.read_body(conn)
167167

168-
event = TestHelpers.decode_event_from_envelope!(body)
168+
event = decode_event_from_envelope!(body)
169169

170170
assert event.culprit == "Sentry.PlugCaptureTest.PhoenixController.error/2"
171171

@@ -175,7 +175,7 @@ defmodule Sentry.PlugCaptureTest do
175175
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
176176
end)
177177

178-
modify_env(:sentry,
178+
modify_app_env(
179179
dsn: "http://public:secret@localhost:#{bypass.port}/1",
180180
"#{__MODULE__.PhoenixEndpoint}": [
181181
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]
@@ -198,14 +198,14 @@ defmodule Sentry.PlugCaptureTest do
198198
Bypass.expect(bypass, fn conn ->
199199
{:ok, body, conn} = Plug.Conn.read_body(conn)
200200

201-
event = TestHelpers.decode_event_from_envelope!(body)
201+
event = decode_event_from_envelope!(body)
202202

203203
assert event.culprit == "Sentry.PlugCaptureTest.PhoenixController.exit/2"
204204
assert event.message == "Uncaught exit - :test"
205205
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
206206
end)
207207

208-
modify_env(:sentry,
208+
modify_app_env(
209209
dsn: "http://public:secret@localhost:#{bypass.port}/1",
210210
"#{__MODULE__.PhoenixEndpoint}": [
211211
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]
@@ -225,14 +225,14 @@ defmodule Sentry.PlugCaptureTest do
225225
Bypass.expect(bypass, fn conn ->
226226
{:ok, body, conn} = Plug.Conn.read_body(conn)
227227

228-
event = TestHelpers.decode_event_from_envelope!(body)
228+
event = decode_event_from_envelope!(body)
229229

230230
assert event.culprit == "Sentry.PlugCaptureTest.PhoenixController.throw/2"
231231
assert event.message == "Uncaught throw - :test"
232232
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
233233
end)
234234

235-
modify_env(:sentry,
235+
modify_app_env(
236236
dsn: "http://public:secret@localhost:#{bypass.port}/1",
237237
"#{__MODULE__.PhoenixEndpoint}": [
238238
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]
@@ -269,7 +269,7 @@ defmodule Sentry.PlugCaptureTest do
269269
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
270270
end)
271271

272-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
272+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
273273

274274
start_supervised!(PhoenixEndpoint)
275275

@@ -280,7 +280,7 @@ defmodule Sentry.PlugCaptureTest do
280280
end
281281

282282
assert_receive {^ref, sentry_body}
283-
event = TestHelpers.decode_event_from_envelope!(sentry_body)
283+
event = decode_event_from_envelope!(sentry_body)
284284

285285
assert event.culprit == "Sentry.PlugCaptureTest.PhoenixController.action_clause_error/2"
286286
assert [exception] = event.exception
@@ -295,12 +295,12 @@ defmodule Sentry.PlugCaptureTest do
295295
Bypass.expect(bypass, fn conn ->
296296
{:ok, body, conn} = Plug.Conn.read_body(conn)
297297

298-
_event = TestHelpers.decode_event_from_envelope!(body)
298+
_event = decode_event_from_envelope!(body)
299299

300300
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
301301
end)
302302

303-
modify_env(:sentry,
303+
modify_app_env(
304304
dsn: "http://public:secret@localhost:#{bypass.port}/1",
305305
"#{__MODULE__.PhoenixEndpoint}": [
306306
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]
@@ -332,12 +332,12 @@ defmodule Sentry.PlugCaptureTest do
332332
Bypass.expect(bypass, fn conn ->
333333
{:ok, body, conn} = Plug.Conn.read_body(conn)
334334

335-
_event = TestHelpers.decode_event_from_envelope!(body)
335+
_event = decode_event_from_envelope!(body)
336336

337337
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
338338
end)
339339

340-
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
340+
modify_app_env(dsn: "http://public:secret@localhost:#{bypass.port}/1")
341341

342342
conn = conn(:get, "/error_route")
343343

@@ -358,12 +358,12 @@ defmodule Sentry.PlugCaptureTest do
358358

359359
Bypass.expect(bypass, fn conn ->
360360
{:ok, body, conn} = Plug.Conn.read_body(conn)
361-
event = TestHelpers.decode_event_from_envelope!(body)
361+
event = decode_event_from_envelope!(body)
362362
assert event.culprit == "Sentry.PlugCaptureTest.PhoenixController.assigns/2"
363363
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
364364
end)
365365

366-
modify_env(:sentry,
366+
modify_app_env(
367367
dsn: "http://public:secret@localhost:#{bypass.port}/1",
368368
"#{__MODULE__.PhoenixEndpoint}": [
369369
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]

0 commit comments

Comments
 (0)