validator icon indicating copy to clipboard operation
validator copied to clipboard

Refactor email test with table-driven test and add more cases

Open daisy1754 opened this issue 8 months ago • 1 comments

Fixes Or Enhances

Added a few test cases around domains that contain number. One thing I realized was validator currently reject address like example.com1 which I believe is allowed per RFC but practically doesn't exist in IANA list. I wasn't sure if it's bug or feature, but at least having test case make it obvious for future reader.

Also refactored TestEmail to use Table Driven Test to avoid code duplication and make test result obvious. Before this, test failed with --- FAIL: TestEmail (0.00s), now it will be like

    --- PASS: TestEmail/Email:_"test_test"@email.com (0.00s)
    --- PASS: TestEmail/Email:_"@email.com (0.00s)
    --- FAIL: TestEmail/Email:[email protected] (0.00s)

Make sure that you've checked the boxes below before you submit PR:

  • [x] Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

daisy1754 avatar Jun 16 '24 14:06 daisy1754