Skip to content

Commit

Permalink
Add test for the get request as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivor committed Oct 1, 2024
1 parent b973b2f commit 22cd028
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/tesla/middleware/meta_logger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ defmodule Tesla.Middleware.MetaLoggerTest do
assert logs =~ "[debug] [#{inspect(Subject)}] #{String.duplicate("b", 100)}\n"
end

test "when the max entry length is given and the logs are split, the metadata is captured with each line" do
test """
For POST requests \
when the max entry length is given and the logs are split \
the metadata is captured with each line
""" do
Logger.metadata(foo: "123123123")

body = String.duplicate("x", 100)
Expand All @@ -246,6 +250,25 @@ defmodule Tesla.Middleware.MetaLoggerTest do
end)
end

test """
For GET requests \
when the max entry length is given and the logs are split \
the metadata is captured with each line
""" do
Logger.metadata(foo: "123123123")

log_lines =
capture_log(fn ->
FakeClient.get("/huge-response", opts: [max_entry_length: 10])
end)
|> String.split("\n\n")

log_lines
|> Enum.each(fn log_line ->
assert log_line =~ "foo=123123123"
end)
end

test "when response is an error, logs the response with error log level" do
logs = capture_log(fn -> FakeClient.get("/error") end)

Expand Down

0 comments on commit 22cd028

Please sign in to comment.