Skip to content

chore: Improve testJSONMarshal#4042

Open
alexandear wants to merge 8 commits intogoogle:masterfrom
alexandear-org:chore/improve-test-json-marshal
Open

chore: Improve testJSONMarshal#4042
alexandear wants to merge 8 commits intogoogle:masterfrom
alexandear-org:chore/improve-test-json-marshal

Conversation

@alexandear
Copy link
Contributor

This PR rewrites testJSONMarshal, so that it properly verifies field marshaling and unmarshaling. Unmarshaling is more complex, as it requires adding multiple options to work around limitations in some of our structs.

I removed tests for structs with only use url field tags, since they are unnecessary.

As #3519 has had no activity since April, I decided to complete this work.

Original author: @exageraldo.
Applied review comments from: @stevehipwell

Fixes #2699
Closes #3519

Co-authored-by: Geraldo Castro <geraldo.castro@thoughtworks.com>
Co-authored-by: Steve Hipwell <steve.hipwell@gmail.com>
@alexandear alexandear force-pushed the chore/improve-test-json-marshal branch from 8b0d697 to ee2f18b Compare February 26, 2026 15:39
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.08%. Comparing base (5f68d54) to head (1ebe1d7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4042   +/-   ##
=======================================
  Coverage   94.08%   94.08%           
=======================================
  Files         207      207           
  Lines       19217    19217           
=======================================
  Hits        18081    18081           
  Misses        938      938           
  Partials      198      198           

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

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @alexandear, this looks great!
I have just a few nits/questions for you, otherwise LGTM.
After that, we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @zyfy29 - @Not-Dhananjay-Mishra

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Feb 26, 2026
@gmlewis gmlewis changed the title chore: Improve testJSONMarshal chore: Improve testJSONMarshal Feb 26, 2026
@alexandear alexandear requested a review from gmlewis February 26, 2026 22:25
@gmlewis
Copy link
Collaborator

gmlewis commented Feb 26, 2026

So moving forward, do developers need to add testJSONMarshal or testJSONMarshalData or testJSONUnmarshalData or a combination of the latter, or how will they decide?

@alexandear
Copy link
Contributor Author

So moving forward, do developers need to add testJSONMarshal or testJSONMarshalData or testJSONUnmarshalData or a combination of the latter, or how will they decide?

That's a good question, and it highlights a somewhat misleading API. I've slightly improved the test functions to make their intent clearer.

In general, developers should use testJSONMarshal, and only in rare cases use testJSONMarshalOnly or testJSONUnmarshalOnly.

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 26, 2026

So moving forward, do developers need to add testJSONMarshal or testJSONMarshalData or testJSONUnmarshalData or a combination of the latter, or how will they decide?

That's a good question, and it highlights a somewhat misleading API. I've slightly improved the test functions to make their intent clearer.

In general, developers should use testJSONMarshal, and only in rare cases use testJSONMarshalOnly or testJSONUnmarshalOnly.

Do you want to give some guidance or recommendations in either CONTRIBUTING.md or in the comments of these functions?

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Excellent! Thank you, @alexandear!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @zyfy29 - @Not-Dhananjay-Mishra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

about testJSONMarshal's behavior

2 participants