Skip to content

Commit 58d94cf

Browse files
committed
Add excoveralls for code coverage
1 parent f996c7d commit 58d94cf

File tree

8 files changed

+80
-3
lines changed

8 files changed

+80
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ erl_crash.dump
55
/doc
66
/priv/plts/*.plt
77
/priv/plts/*.plt.hash
8+
/cover

coveralls.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"coverage_options": {
3+
"treat_no_relevant_lines_as_covered": true
4+
}
5+
}

mix.exs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ defmodule Sentry.Mixfile do
1919
plt_add_deps: :app_tree,
2020
plt_add_apps: [:mix, :ex_unit]
2121
],
22+
test_coverage: [tool: ExCoveralls],
23+
preferred_cli_env: [
24+
"coveralls.html": :test
25+
],
2226
name: "Sentry",
2327
docs: [
2428
extra_section: "Guides",
@@ -73,12 +77,15 @@ defmodule Sentry.Mixfile do
7377
{:jason, "~> 1.1", optional: true},
7478
{:plug, "~> 1.6", optional: true},
7579
{:plug_cowboy, "~> 2.3", optional: true},
80+
81+
# Dev and test dependencies
82+
{:bypass, "~> 2.0", only: [:test]},
7683
{:dialyxir, "~> 1.0", only: [:test, :dev], runtime: false},
7784
{:ex_doc, "~> 0.29.0", only: :dev},
78-
{:bypass, "~> 2.0", only: [:test]},
85+
{:excoveralls, "~> 0.17.1", only: [:test]},
86+
{:mox, "~> 1.0", only: [:test]},
7987
{:phoenix, "~> 1.5", only: [:test]},
80-
{:phoenix_html, "~> 2.0", only: [:test]},
81-
{:mox, "~> 1.0", only: [:test]}
88+
{:phoenix_html, "~> 2.0", only: [:test]}
8289
]
8390
end
8491

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"earmark_parser": {:hex, :earmark_parser, "1.4.32", "fa739a0ecfa34493de19426681b23f6814573faee95dfd4b4aafe15a7b5b32c6", [:mix], [], "hexpm", "b8b0dd77d60373e77a3d7e8afa598f325e49e8663a51bcc2b88ef41838cca755"},
1010
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
1111
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
12+
"excoveralls": {:hex, :excoveralls, "0.17.1", "83fa7906ef23aa7fc8ad7ee469c357a63b1b3d55dd701ff5b9ce1f72442b2874", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "95bc6fda953e84c60f14da4a198880336205464e75383ec0f570180567985ae0"},
1213
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
1314
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
1415
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},

test/config_test.exs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule Sentry.ConfigTest do
22
use ExUnit.Case
3+
import ExUnit.CaptureIO
34
import Sentry.TestEnvironmentHelper
45
alias Sentry.Config
56

@@ -36,6 +37,11 @@ defmodule Sentry.ConfigTest do
3637
modify_env(:sentry, included_environments: [:test, :dev])
3738
assert Config.included_environments() == ["test", "dev"]
3839
end
40+
41+
test "defaults to [\"prod\"]" do
42+
delete_env(:sentry, :included_environments)
43+
assert Config.included_environments() == ["prod"]
44+
end
3945
end
4046

4147
describe "environment_name/0" do
@@ -57,4 +63,38 @@ defmodule Sentry.ConfigTest do
5763
end
5864
end
5965
end
66+
67+
describe "validate_log_level!/0" do
68+
test "raises for invalid log levels" do
69+
modify_env(:sentry, log_level: :invalid)
70+
71+
assert_raise ArgumentError, ":invalid is not a valid :log_level configuration", fn ->
72+
Config.validate_log_level!()
73+
end
74+
end
75+
end
76+
77+
describe "assert_dsn_has_no_query_params!/0" do
78+
test "raises if DSN has query params" do
79+
modify_env(:sentry, dsn: "https://public:[email protected]/1?send_max_attempts=5")
80+
81+
assert_raise ArgumentError, ~r/using a Sentry DSN/, fn ->
82+
Config.assert_dsn_has_no_query_params!()
83+
end
84+
end
85+
end
86+
87+
describe "warn_for_deprecated_env_vars!/0" do
88+
test "emits the right warning" do
89+
delete_env(:sentry, :included_environments)
90+
modify_system_env(%{"SENTRY_INCLUDED_ENVIRONMENTS" => "test,dev"})
91+
92+
output =
93+
capture_io(:stderr, fn ->
94+
assert :ok = Config.warn_for_deprecated_env_vars!()
95+
end)
96+
97+
assert output =~ "setting SENTRY_INCLUDED_ENVIRONMENTS is deprecated"
98+
end
99+
end
60100
end

test/event_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ defmodule Sentry.EventTest do
381381
:cowlib,
382382
:dialyxir,
383383
:erlex,
384+
:excoveralls,
384385
:hackney,
385386
:idna,
386387
:jason,

test/sentry_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,13 @@ defmodule SentryTest do
8585
assert {event_id, nil} = Sentry.get_last_event_id_and_source()
8686
assert is_binary(event_id)
8787
end
88+
89+
test "ignores events without message and exception" do
90+
log =
91+
capture_log(fn ->
92+
assert Sentry.send_event(Sentry.Event.create_event([])) == :ignored
93+
end)
94+
95+
assert log =~ "Sentry: unable to parse exception"
96+
end
8897
end

test/support/test_environment_helper.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ defmodule Sentry.TestEnvironmentHelper do
1414
end)
1515
end
1616

17+
def delete_env(app, key) do
18+
original_env = Application.fetch_env(app, key)
19+
20+
Application.delete_env(app, key)
21+
22+
ExUnit.Callbacks.on_exit(fn ->
23+
case original_env do
24+
{:ok, val} -> Application.put_env(app, key, val)
25+
:error -> :ok
26+
end
27+
end)
28+
end
29+
1730
def modify_system_env(overrides) when is_map(overrides) do
1831
original_env = System.get_env()
1932
System.put_env(overrides)

0 commit comments

Comments
 (0)