Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
package validator_test
import (
"testing"
"fiskerinc.com/modules/validator"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func Test_validateEmail(t *testing.T) {
tests := map[string]struct {
emailsList []string
expErr error
}{
"valid": {
emailsList: []string{
"simple@example.com",
"very.common@example.com",
"disposable.style.email.with+symbol@example.com",
"other.email-with-hyphen@example.com",
"fully-qualified-domain@example.com",
"user.name+tag+sorting@example.com",
"x@example.com",
"example-indeed@strange-example.com",
"example@s.example",
"user-@example.org",
"2abc.d@mail.com",
},
},
"invalid": {
emailsList: []string{
"1234567890123456789012345678901234567890123456789012345678901234+x@example.com",
"abc.@mail.com",
"abc..def@mail.com",
`"".abc@mail.com`,
"abc#def@mail.com",
"abc.def@mail.c",
"abc.def@mail#archive.com",
"abc.def@mail",
"abc.def@mail..com",
},
expErr: errors.New("Key: '' Error:Field validation for '' failed on the 'email' tag"),
},
}
v := validator.GetValidator()
for tname, tt := range tests {
t.Run(tname, func(t *testing.T) {
for _, email := range tt.emailsList {
err := v.Var(email, "email")
if err != nil && tt.expErr != nil {
assert.Equal(t, tt.expErr.Error(), err.Error())
continue
}
assert.Equal(t, tt.expErr, err)
}
})
}
}