Open DavidAntaramian opened 7 years ago
@mitchellhenke Not quite. Your change allows us to test what is received from Logger calls. What I want to be able to test here is the output we generate via our formatter. More like a full integration test.
More directly, I want to test that, given:
ip_address = "127.0.0.1"
port = 61248
session_id = "gzs78135"
Timber.add_context(remote_peer: %{ip_address: ip_address, port: port, session_id: session_id})
Logger.info fn ->
"Timed out while waiting for data from remote peer"
end
the output (somewhat) matches:
Timed out while waiting for data from remote peer @metadata {"level":"info","dt":"2018-04-27T16:19:57.982531Z","context":{"custom":{"remote_peer":{"session_id":"gzs78135","port":61248,"ip_address":"127.0.0.1"}}},"$schema":"https://raw.githubusercontent.com/timberio/log-event-json-schema/v3.1.1/schema.json"}
Granted that matching output like that is really difficult 😕 The key though is to have tests that ensure that changes don't break the core functionality.
ah okay, darn. Thanks for the explanation
We can use https://hexdocs.pm/ex_unit/ExUnit.CaptureLog.html#content to capture logs, but for some reason it's outputting ANSI data in the log data when it shouldn't be. Once that's resolved, this should resolve a lot of issues around testing methods.