Skip to content

test: enhance error accumulator and form builder tests, add marshaller tests #999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Whitea029
Copy link

Describe the change
enhance error accumulator and form builder tests, add marshaller tests

Describe your solution
added some edge case tests to improve test coverage

Issue: #997

Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.48%. Comparing base (4d2e7ab) to head (ebfffde).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #999      +/-   ##
==========================================
+ Coverage   85.93%   86.48%   +0.54%     
==========================================
  Files          43       43              
  Lines        2268     2271       +3     
==========================================
+ Hits         1949     1964      +15     
+ Misses        300      287      -13     
- Partials       19       20       +1     

☔ 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.

@sashabaranov sashabaranov requested a review from Copilot May 14, 2025 10:01
Copy link

@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 enhances test coverage for the JSON marshaller/unmarshaler, error accumulator, and form builder modules by introducing additional edge case tests and refining error handling.

  • Adds tests for valid and invalid JSON (un)marshalling
  • Introduces extensive tests for form builder functionality including file uploads, special characters, and error propagation
  • Refactors error accumulator tests to verify multiple write scenarios

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/unmarshaler_test.go New tests for JSON unmarshalling including normal, invalid, and nil inputs.
internal/marshaller_test.go New tests for JSON marshalling with normal, invalid, and empty values.
internal/form_builder_test.go Additional tests for form builder behavior in various scenarios.
internal/form_builder.go Adds an error check in WriteField to disallow an empty fieldname.
internal/error_accumulator_test.go Refactored tests to verify error accumulation behavior.
Comments suppressed due to low confidence (1)

internal/form_builder_test.go:44

  • The code references errors.New but does not import the 'errors' package, which may result in a compilation failure. Please add 'import "errors"' to the import block.
errorMock := errors.New("mock close error")

@Whitea029 Whitea029 requested a review from Copilot May 15, 2025 10:46
Copy link

@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 enhances test coverage for error accumulation, form building, and marshalling behavior by adding new test cases and edge case verifications.

  • Added tests for JSON unmarshalling/marshalling functionality covering normal, invalid, and empty input scenarios.
  • Extended form builder tests to include multiple file uploads, special characters, concurrent file handling, and field edge cases.
  • Updated error accumulator tests to validate sequential error writes and buffer initialization.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/unmarshaler_test.go New tests for verifying correct and erroneous JSON unmarshalling behavior.
internal/marshaller_test.go New tests for validating JSON marshalling, including handling of unsupported types & nil.
internal/form_builder_test.go Extended tests covering file uploads, field writing errors, and special filename handling.
internal/form_builder.go Added a check to ensure field names are not empty in WriteField.
internal/error_accumulator_test.go Updated tests to verify multiple error writes and correct initial buffer state.
Comments suppressed due to low confidence (1)

internal/error_accumulator_test.go:18

  • [nitpick] Ensure that the concatenation order of error messages in the accumulator is guaranteed by design; if not, consider adding a delimiter or additional checks in the test.
expected := "{\"error\": \"test1\"}{\"error\": \"test2\"}"

@Whitea029 Whitea029 requested a review from Copilot May 16, 2025 04:37
Copy link

@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 enhances test coverage by adding new tests for the error accumulator, form builder, and marshaller, and by improving existing tests for JSON unmarshaling.

  • Added tests for normal, invalid, and edge case scenarios for JSON unmarshaler and marshaller.
  • Extended form builder tests to cover file uploads, content type validation, and error propagation.
  • Updated error accumulator tests for improved error concatenation validation.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/unmarshaler_test.go Tests verifying correct JSON unmarshaling behavior in various cases.
internal/marshaller_test.go Tests validating JSON marshalling including handling of invalid inputs.
internal/form_builder_test.go New tests covering form builder behaviors like file uploads and error handling.
internal/form_builder.go Added fieldname validation to prevent empty field names.
internal/error_accumulator_test.go Updated tests for error accumulation and concatenation behavior.

Comment on lines +91 to +94
body := &bytes.Buffer{}
builder := NewFormBuilder(body)

t.Run("MultipleFiles", func(t *testing.T) {
Copy link
Preview

Copilot AI May 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider initializing a new FormBuilder within each subtest in TestMultiPartFormUploads to avoid potential side-effects from sharing mutable state across subtests.

Suggested change
body := &bytes.Buffer{}
builder := NewFormBuilder(body)
t.Run("MultipleFiles", func(t *testing.T) {
t.Run("MultipleFiles", func(t *testing.T) {
body := &bytes.Buffer{}
builder := NewFormBuilder(body)

Copilot uses AI. Check for mistakes.

@Whitea029 Whitea029 requested a review from kmesiab May 17, 2025 05:05
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.

2 participants