diff --git a/test/tesla/middleware/meta_logger_test.exs b/test/tesla/middleware/meta_logger_test.exs index 8db95d5..6cd08c4 100644 --- a/test/tesla/middleware/meta_logger_test.exs +++ b/test/tesla/middleware/meta_logger_test.exs @@ -1,6 +1,8 @@ defmodule Tesla.Middleware.MetaLoggerTest do use ExUnit.Case, async: true + require Logger + import ExUnit.CaptureLog alias Tesla.Middleware.MetaLogger, as: Subject @@ -227,6 +229,46 @@ defmodule Tesla.Middleware.MetaLoggerTest do assert logs =~ "[debug] [#{inspect(Subject)}] #{String.duplicate("b", 100)}\n" end + 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) + + log_lines = + capture_log(fn -> + FakeClient.post("/huge-response", body, 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 """ + 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)