Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Verify that metadata is captured with each slice of large logs #21

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions test/tesla/middleware/meta_logger_test.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading