go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
17k stars 1.33k forks source link

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

Open daisy1754 opened 5 months ago

daisy1754 commented 5 months ago

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:_example@email.com1 (0.00s)

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

@go-playground/validator-maintainers

coveralls commented 5 months ago

Coverage Status

coverage: 74.291%. remained the same when pulling ea408f3f5029ec201885d9a92d11b866ee0d7328 on daisy1754:kazuki/more_email_test into a947377040f8ebaee09f20d09a745ec369396793 on go-playground:master.