Skip to content

Commit 4667ec4

Browse files
committed
Fix coverage
1 parent 516d588 commit 4667ec4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/logger_json/formatter/metadata.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule LoggerJSON.Formatter.Metadata do
1818
end
1919

2020
def update_metadata_selector({:from_application_env, other}, _processed_keys) do
21-
raise """
21+
raise ArgumentError, """
2222
Invalid value for `:metadata` option: `{:from_application_env, #{inspect(other)}}`.
2323
2424
The value must be a tuple with the application and module name,

test/logger_json/formatter/metadata_test.exs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,49 @@ defmodule LoggerJSON.Formatter.MetadataTest do
33
import LoggerJSON.Formatter.Metadata
44

55
describe "update_metadata_selector/2" do
6+
# test this
7+
# def update_metadata_selector({:from_application_env, {app, module}, path}, processed_keys) do
8+
# Application.fetch_env!(app, module)
9+
# |> get_in(path)
10+
# |> update_metadata_selector(processed_keys)
11+
# end
12+
13+
# def update_metadata_selector({:from_application_env, {app, module}}, processed_keys) do
14+
# Application.fetch_env!(app, module)
15+
# |> update_metadata_selector(processed_keys)
16+
# end
17+
18+
# def update_metadata_selector({:from_application_env, other}, _processed_keys) do
19+
# raise """
20+
# Invalid value for `:metadata` option: `{:from_application_env, #{inspect(other)}}`.
21+
22+
# The value must be a tuple with the application and module name,
23+
# and an optional path to the metadata option.
24+
25+
# Eg.: `{:from_application_env, {:logger, :default_formatter}, [:metadata]}`
26+
# """
27+
# end
28+
29+
test "takes metadata from application env" do
30+
Application.put_env(:logger_json, :test_metadata_key, [:foo])
31+
32+
assert update_metadata_selector({:from_application_env, {:logger_json, :test_metadata_key}}, []) ==
33+
[:foo]
34+
35+
Application.put_env(:logger_json, :test_metadata_key, %{metadata: [:foo]})
36+
37+
assert update_metadata_selector({:from_application_env, {:logger_json, :test_metadata_key}, [:metadata]}, []) ==
38+
[:foo]
39+
end
40+
41+
test "raises if metadata is not a tuple with the application and module name" do
42+
message = ~r/Invalid value for `:metadata` option: `{:from_application_env, :foo}`./
43+
44+
assert_raise ArgumentError, message, fn ->
45+
update_metadata_selector({:from_application_env, :foo}, [])
46+
end
47+
end
48+
649
test "takes metadata :all rule and updates it to exclude the given keys" do
750
assert update_metadata_selector(:all, [:ansi_color]) == {:all_except, [:ansi_color]}
851
end

0 commit comments

Comments
 (0)