Goal
Add tests for the logging package. There is currently no internal/logging/logging_test.go.
Files
internal/logging/logging.go (read)
internal/logging/logging_test.go (new)
Changes
Add at least:
TestLoggerCreation: call the logger setup function, assert a non-nil logger is returned and is wired to the expected handler.
TestLogLevelConfiguration: configure debug, info, warn, and error levels, then emit messages and assert only the appropriate ones appear in captured output.
TestLoggerOutput: redirect output to a bytes.Buffer, log a structured message, and assert the resulting JSON has the expected fields and level.
Use a slog.NewJSONHandler with a buffer if the logging package supports injection. If it does not, document that limitation and test what is observable.
Verification
go test -v -race ./internal/logging/...
Dependencies
None.
Goal
Add tests for the logging package. There is currently no
internal/logging/logging_test.go.Files
internal/logging/logging.go(read)internal/logging/logging_test.go(new)Changes
Add at least:
TestLoggerCreation: call the logger setup function, assert a non-nil logger is returned and is wired to the expected handler.TestLogLevelConfiguration: configure debug, info, warn, and error levels, then emit messages and assert only the appropriate ones appear in captured output.TestLoggerOutput: redirect output to abytes.Buffer, log a structured message, and assert the resulting JSON has the expected fields and level.Use a
slog.NewJSONHandlerwith a buffer if the logging package supports injection. If it does not, document that limitation and test what is observable.Verification
Dependencies
None.