Skip to content

Commit f996c7d

Browse files
committed
Clean up Sentry.Config
1 parent d33bf19 commit f996c7d

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

lib/sentry/config.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ defmodule Sentry.Config do
231231
end
232232

233233
defp get_config_from_app_or_system_env(app_key, system_env_key) do
234-
case Application.fetch_env(:sentry, app_key) do
235-
{:ok, {:system, env_key}} ->
234+
case Application.get_env(:sentry, app_key, nil) do
235+
{:system, env_key} ->
236236
raise ArgumentError, """
237237
using {:system, env} as a configuration value is not supported since v9.0.0 of this \
238238
library. Move the configuration for #{inspect(app_key)} to config/runtime.exs, \
@@ -244,16 +244,16 @@ defmodule Sentry.Config do
244244
245245
"""
246246

247-
{:ok, value} ->
248-
value
249-
250-
:error ->
247+
nil ->
251248
if value = System.get_env(system_env_key) do
252249
Application.put_env(:sentry, app_key, value)
253250
value
254251
else
255252
nil
256253
end
254+
255+
value ->
256+
value
257257
end
258258
end
259259
end

test/config_test.exs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,51 @@ defmodule Sentry.ConfigTest do
33
import Sentry.TestEnvironmentHelper
44
alias Sentry.Config
55

6-
test "retrieves from application environment" do
7-
dsn = "https://public:[email protected]/1"
8-
modify_env(:sentry, dsn: dsn)
9-
assert dsn == Config.dsn()
10-
end
11-
12-
test "retrieves from system environment" do
13-
dsn = "https://public:[email protected]/1"
14-
modify_system_env(%{"SENTRY_DSN" => dsn})
6+
describe "dsn/0" do
7+
test "retrieves from application environment" do
8+
dsn = "https://public:[email protected]/1"
9+
modify_env(:sentry, dsn: dsn)
10+
assert Config.dsn() == dsn
11+
end
1512

16-
assert dsn == Config.dsn()
17-
end
13+
test "retrieves from system environment" do
14+
dsn = "https://public:[email protected]/1"
15+
modify_system_env(%{"SENTRY_DSN" => dsn})
16+
assert Config.dsn() == dsn
17+
end
1818

19-
test "sets application env if found in system env" do
20-
dsn = "https://public:[email protected]/1"
21-
modify_system_env(%{"SENTRY_DSN" => dsn})
19+
test "sets application env if found in system env" do
20+
dsn = "https://public:[email protected]/1"
21+
modify_system_env(%{"SENTRY_DSN" => dsn})
2222

23-
assert Config.dsn() == dsn
24-
assert Application.get_env(:sentry, :dsn) == dsn
23+
assert Config.dsn() == dsn
24+
assert Application.get_env(:sentry, :dsn) == dsn
25+
end
2526
end
2627

27-
describe "source_code_path_pattern" do
28+
describe "source_code_path_pattern/0" do
2829
test "returns default when not configured" do
29-
assert "**/*.ex" == Config.source_code_path_pattern()
30+
assert Config.source_code_path_pattern() == "**/*.ex"
3031
end
3132
end
3233

33-
describe "included_environments" do
34+
describe "included_environments/0" do
3435
test "retrieves from app env" do
3536
modify_env(:sentry, included_environments: [:test, :dev])
36-
assert ["test", "dev"] == Config.included_environments()
37+
assert Config.included_environments() == ["test", "dev"]
3738
end
3839
end
3940

40-
describe "environment_name" do
41+
describe "environment_name/0" do
4142
test "retrieves from app env" do
4243
modify_env(:sentry, environment_name: "test")
43-
assert "test" == Config.environment_name()
44+
assert Config.environment_name() == "test"
4445
end
4546

4647
test "retrieves from system env" do
48+
modify_env(:sentry, environment_name: nil)
4749
modify_system_env(%{"SENTRY_ENVIRONMENT" => "test"})
48-
assert :test == Config.environment_name()
50+
assert Config.environment_name() == "test"
4951
end
5052

5153
test "raises if not set" do

0 commit comments

Comments
 (0)