Skip to content

tests: add internal/logging tests for level config and output format #712

Description

@wolf31o2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions