Skip to content

test(baked_in): add regression test for postcode_iso3166_alpha2_field issue #1314 - #1586

Open
64johnlee wants to merge 1 commit into
go-playground:masterfrom
64johnlee:fix-postcode-alpha2-field-1314
Open

test(baked_in): add regression test for postcode_iso3166_alpha2_field issue #1314#1586
64johnlee wants to merge 1 commit into
go-playground:masterfrom
64johnlee:fix-postcode-alpha2-field-1314

Conversation

@64johnlee

Copy link
Copy Markdown

Summary

Adds a regression test (TestPostCodeByIso3166Alpha2Field_Issue1314) that directly reproduces the scenario from issue #1314: using postcode_iso3166_alpha2_field with WithRequiredStructEnabled().

The underlying bug (missing postcodeRegexInit.Do(initPostcodes) call in isPostcodeByIso3166Alpha2Field) was introduced by PR #1270 and has since been fixed in HEAD. However, no test existed for the exact WithRequiredStructEnabled() scenario reported in the issue, leaving the door open for future regressions.

Closes #1314

Changes

  • validator_test.go — adds TestPostCodeByIso3166Alpha2Field_Issue1314 covering the valid and invalid postcode cases with WithRequiredStructEnabled()

Test plan

  • PATH=/home/user/go/bin:$PATH go test ./... passes (all 24 packages)
  • TestPostCodeByIso3166Alpha2Field_Issue1314 passes, confirming the fix is in place
  • All existing TestPostCodeByIso3166Alpha2Field* tests continue to pass

… issue go-playground#1314

Adds TestPostCodeByIso3166Alpha2Field_Issue1314 to confirm that
postcode_iso3166_alpha2_field works correctly when WithRequiredStructEnabled()
is used — the exact scenario broken in v10.21.0 after PR go-playground#1270 changed
iso3166 maps from map[string]bool to map[string]struct{}.

The underlying fix (adding postcodeRegexInit.Do(initPostcodes) before the
dict lookup in isPostcodeByIso3166Alpha2Field) is already present in HEAD;
this test prevents future regressions.

Closes go-playground#1314

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@64johnlee
64johnlee requested a review from a team as a code owner June 9, 2026 16:06
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.

Bug: postcode_iso3166_alpha2_field validation broken in v10.21.0

1 participant