Skip to content

Commit

Permalink
Fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDryga committed Aug 26, 2024
1 parent 516d588 commit 4667ec4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/logger_json/formatter/metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule LoggerJSON.Formatter.Metadata do
end

def update_metadata_selector({:from_application_env, other}, _processed_keys) do
raise """
raise ArgumentError, """
Invalid value for `:metadata` option: `{:from_application_env, #{inspect(other)}}`.
The value must be a tuple with the application and module name,
Expand Down
43 changes: 43 additions & 0 deletions test/logger_json/formatter/metadata_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,49 @@ defmodule LoggerJSON.Formatter.MetadataTest do
import LoggerJSON.Formatter.Metadata

describe "update_metadata_selector/2" do
# test this
# def update_metadata_selector({:from_application_env, {app, module}, path}, processed_keys) do
# Application.fetch_env!(app, module)
# |> get_in(path)
# |> update_metadata_selector(processed_keys)
# end

# def update_metadata_selector({:from_application_env, {app, module}}, processed_keys) do
# Application.fetch_env!(app, module)
# |> update_metadata_selector(processed_keys)
# end

# def update_metadata_selector({:from_application_env, other}, _processed_keys) do
# raise """
# Invalid value for `:metadata` option: `{:from_application_env, #{inspect(other)}}`.

# The value must be a tuple with the application and module name,
# and an optional path to the metadata option.

# Eg.: `{:from_application_env, {:logger, :default_formatter}, [:metadata]}`
# """
# end

test "takes metadata from application env" do
Application.put_env(:logger_json, :test_metadata_key, [:foo])

assert update_metadata_selector({:from_application_env, {:logger_json, :test_metadata_key}}, []) ==
[:foo]

Application.put_env(:logger_json, :test_metadata_key, %{metadata: [:foo]})

assert update_metadata_selector({:from_application_env, {:logger_json, :test_metadata_key}, [:metadata]}, []) ==
[:foo]
end

test "raises if metadata is not a tuple with the application and module name" do
message = ~r/Invalid value for `:metadata` option: `{:from_application_env, :foo}`./

assert_raise ArgumentError, message, fn ->
update_metadata_selector({:from_application_env, :foo}, [])
end
end

test "takes metadata :all rule and updates it to exclude the given keys" do
assert update_metadata_selector(:all, [:ansi_color]) == {:all_except, [:ansi_color]}
end
Expand Down

0 comments on commit 4667ec4

Please sign in to comment.