Skip to content

Conversation

SVilgelm
Copy link
Member

@SVilgelm SVilgelm commented Sep 8, 2025

Add comprehensive tests for the HTTP response writer, template
execution, and structured logging middleware.

Key changes:

  • Add TestResponsesWriter_FileAndJSONHeader to verify serving file
    contents, status code, JSON content-type, and custom headers.
  • Add TestResponsesWriter_RepeatLogic to assert Repeat behavior keeps
    a response for N calls before advancing to the next response.
  • Add TestResponsesWriter_NotFoundWhenExhausted to ensure a 404 is
    returned when no responses remain.
  • Add TestResponsesWriter_FileReadError to check 500 on missing file
    and that the error message includes the filename.
  • Add TestResponsesWriter_JSONDoesNotOverrideExistingContentType to
    confirm IsJSON does not overwrite an explicitly set Content-Type.
  • Add TestExecuteTemplate_Success and TestExecuteTemplate_ParseError to
    validate template execution and parse error handling.
  • Add TestStructuredLogger_BasicFields and helpers to validate JSON
    structured logging output and basic middleware behavior.

Also add testLogger helper for building a JSON logger writing to a
buffer. Tests use httptest, temporary files, and explicit header
assertions to make behavior deterministic.

@Copilot Copilot AI review requested due to automatic review settings September 8, 2025 15:28
Copilot

This comment was marked as outdated.

Add comprehensive tests for the HTTP response writer, template
execution, and structured logging middleware.

Key changes:
- Add TestResponsesWriter_FileAndJSONHeader to verify serving file
  contents, status code, JSON content-type, and custom headers.
- Add TestResponsesWriter_RepeatLogic to assert Repeat behavior keeps
  a response for N calls before advancing to the next response.
- Add TestResponsesWriter_NotFoundWhenExhausted to ensure a 404 is
  returned when no responses remain.
- Add TestResponsesWriter_FileReadError to check 500 on missing file
  and that the error message includes the filename.
- Add TestResponsesWriter_JSONDoesNotOverrideExistingContentType to
  confirm IsJSON does not overwrite an explicitly set Content-Type.
- Add TestExecuteTemplate_Success and TestExecuteTemplate_ParseError to
  validate template execution and parse error handling.
- Add TestStructuredLogger_BasicFields and helpers to validate JSON
  structured logging output and basic middleware behavior.

Also add testLogger helper for building a JSON logger writing to a
buffer. Tests use httptest, temporary files, and explicit header
assertions to make behavior deterministic.
Update responses_writer_test.go

Co-authored-by: Copilot <[email protected]>
Update responses_writer_test.go

Co-authored-by: Copilot <[email protected]>
@SVilgelm SVilgelm force-pushed the test/add-responses-templ-logger-tests branch from 19d02c7 to 4423388 Compare September 8, 2025 15:37
@SVilgelm SVilgelm requested a review from Copilot September 8, 2025 15:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive unit tests for HTTP response handling, template execution, and structured logging middleware. The tests focus on verifying core functionality including file serving, response repetition logic, error handling, and JSON logging output.

  • Add thorough test coverage for ResponsesWriter behavior including file serving, repeat logic, and error scenarios
  • Add template execution tests for both success and error cases
  • Add structured logging middleware tests with JSON output validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@SVilgelm SVilgelm enabled auto-merge (squash) September 8, 2025 15:39
@SVilgelm SVilgelm linked an issue Sep 8, 2025 that may be closed by this pull request
@SVilgelm SVilgelm merged commit 82f623b into main Sep 8, 2025
7 checks passed
@SVilgelm SVilgelm deleted the test/add-responses-templ-logger-tests branch September 8, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add tests

1 participant