Skip to content

test(render): add comprehensive error handling tests#4541

Open
Amirhf1 wants to merge 1 commit intogin-gonic:masterfrom
Amirhf1:test/render-error-handling
Open

test(render): add comprehensive error handling tests#4541
Amirhf1 wants to merge 1 commit intogin-gonic:masterfrom
Amirhf1:test/render-error-handling

Conversation

@Amirhf1
Copy link
Contributor

@Amirhf1 Amirhf1 commented Feb 18, 2026

Summary:

This PR adds comprehensive error handling tests for the render package, addressing the TODO comment requesting additional error test cases. The new tests ensure that all render types properly handle and report errors in edge cases.

Changes:
Added 6 new error handling test cases:

  • TestRenderXMLError: Validates that XML renderer properly handles unsupported types (e.g., channels) and returns meaningful error messages
  • TestRenderDataError: Tests error propagation when the underlying writer fails during Data rendering
  • TestRenderBSONError: Ensures BSON renderer handles unsupported types gracefully
  • TestRenderBSONWriteError: Verifies error handling when writing BSON data fails
  • TestRenderHTMLTemplateError: Tests template execution errors with invalid field access
  • TestRenderHTMLTemplateExecuteError: Validates error handling for nested field access errors in templates

Additionally, removed the TODO unit tests comment as the error cases are now properly covered.

Motivation:
Error handling tests are crucial for ensuring the framework behaves predictably when encountering invalid inputs or system failures. These tests improve confidence in the render package's robustness and help catch potential regressions.

Related Issues:
Addresses the TODO comment in render/render_test.go line 26-27.

Add error case tests for XML, Data, BSON, and HTML renderers to improve test coverage and ensure proper error handling:

- TestRenderXMLError: validates XML marshal error handling for unsupported types
- TestRenderDataError: validates Data write error handling
- TestRenderBSONError: validates BSON marshal error handling for unsupported types
- TestRenderBSONWriteError: validates BSON write error handling
- TestRenderHTMLTemplateError: validates HTML template execution error with invalid field access
- TestRenderHTMLTemplateExecuteError: validates HTML template execution error with invalid nested field

All tests pass and maintain 100% coverage for the render package.
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.07%. Comparing base (3dc1cd6) to head (f7f1f07).
⚠️ Report is 249 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4541      +/-   ##
==========================================
- Coverage   99.21%   99.07%   -0.14%     
==========================================
  Files          42       46       +4     
  Lines        3182     3038     -144     
==========================================
- Hits         3157     3010     -147     
- Misses         17       19       +2     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 99.07% <ø> (?)
-tags go_json 98.93% <ø> (?)
-tags nomsgpack 98.99% <ø> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.24 99.07% <ø> (?)
go-1.25 99.01% <ø> (?)
macos-latest 99.01% <ø> (-0.21%) ⬇️
ubuntu-latest 99.07% <ø> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant

Comments