github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/ev/validator_blacklist_email_test.go (about) 1 package ev 2 3 import ( 4 "github.com/go-email-validator/go-email-validator/pkg/ev/contains" 5 "github.com/go-email-validator/go-email-validator/pkg/ev/evmail" 6 "github.com/go-email-validator/go-email-validator/pkg/ev/utils" 7 "reflect" 8 "testing" 9 ) 10 11 func Test_blackListEmailsValidator_Validate(t *testing.T) { 12 type fields struct { 13 d contains.InSet 14 } 15 type args struct { 16 email evmail.Address 17 } 18 tests := []struct { 19 name string 20 fields fields 21 args args 22 want ValidationResult 23 }{ 24 { 25 name: "email is valid", 26 fields: fields{ 27 d: mockContains{t: t, want: validEmail.String(), ret: false}, 28 }, 29 args: args{ 30 email: validEmail, 31 }, 32 want: NewResult(true, nil, nil, BlackListEmailsValidatorName), 33 }, 34 { 35 name: "email is invalid", 36 fields: fields{ 37 d: mockContains{t: t, want: validEmail.String(), ret: true}, 38 }, 39 args: args{ 40 email: validEmail, 41 }, 42 want: NewResult(false, utils.Errs(BlackListEmailsError{}), nil, BlackListEmailsValidatorName), 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 w := NewBlackListEmailsValidator(tt.fields.d) 48 if got := w.Validate(NewInput(tt.args.email)); !reflect.DeepEqual(got, tt.want) { 49 t.Errorf("Validate() = %v, want %v", got, tt.want) 50 } 51 }) 52 } 53 } 54 55 func TestBlackListEmailsError_Error(t *testing.T) { 56 tests := []struct { 57 name string 58 want string 59 }{ 60 { 61 name: "success", 62 want: BlackListEmailsErr, 63 }, 64 } 65 for _, tt := range tests { 66 t.Run(tt.name, func(t *testing.T) { 67 bl := BlackListEmailsError{} 68 if got := bl.Error(); got != tt.want { 69 t.Errorf("Error() = %v, want %v", got, tt.want) 70 } 71 }) 72 } 73 }