From 22cd028f2cbec8b209feb46740e19d32a910a82d Mon Sep 17 00:00:00 2001 From: Ivor Paul Date: Tue, 1 Oct 2024 14:13:39 +0200 Subject: [PATCH] Add test for the get request as well. --- test/tesla/middleware/meta_logger_test.exs | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/tesla/middleware/meta_logger_test.exs b/test/tesla/middleware/meta_logger_test.exs index ba112ae..6cd08c4 100644 --- a/test/tesla/middleware/meta_logger_test.exs +++ b/test/tesla/middleware/meta_logger_test.exs @@ -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) @@ -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)