github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/presentation/check-if-email-exist/dep_functional_test.go (about)

     1  package checkifemailexist
     2  
     3  import (
     4  	"github.com/emirpasic/gods/sets/hashset"
     5  	"github.com/go-email-validator/go-email-validator/pkg/ev"
     6  	"github.com/go-email-validator/go-email-validator/pkg/ev/evmail"
     7  	"github.com/go-email-validator/go-email-validator/pkg/ev/evtests"
     8  	"github.com/go-email-validator/go-email-validator/pkg/presentation/converter"
     9  	"github.com/go-email-validator/go-email-validator/pkg/presentation/test"
    10  	"reflect"
    11  	"sort"
    12  	"testing"
    13  )
    14  
    15  func TestMain(m *testing.M) {
    16  	evtests.TestMain(m)
    17  }
    18  
    19  func TestDepConverter_Convert(t *testing.T) {
    20  	evtests.FunctionalSkip(t)
    21  
    22  	validator := NewDepValidator(nil)
    23  	d := NewDepConverterDefault()
    24  
    25  	tests := make([]DepPresentation, 0)
    26  	test.DepPresentations(t, &tests, "")
    27  
    28  	// Some data or functional cannot be matched, see more nearby DepPresentation of emails
    29  	skipEmail := hashset.New(
    30  		// TODO problem with SMTP, CIEE think that email is not is_catch_all. Need to run and research source code on RUST
    31  		"sewag33689@itymail.com",
    32  		/* TODO add proxy to test
    33  		5.7.1 Service unavailable, Client host [94.181.152.110] blocked using Spamhaus. To request removal from this list see https://www.spamhaus.org/query/ip/94.181.152.110 (AS3130). [BN8NAM12FT053.eop-nam12.prod.protection.outlook.com]
    34  		*/
    35  		"salestrade86@hotmail.com",
    36  		"monicaramirezrestrepo@hotmail.com",
    37  		// TODO CIEE banned
    38  		"credit@mail.ru",
    39  		// TODO need check source code
    40  		"asdasd@tradepro.net",
    41  		// TODO need check source code
    42  		"y-numata@senko.ed.jp",
    43  		"theofanisgiotis@12pm.gr",
    44  		"theofanis.giot2is@12pm.gr",
    45  		"derduzikne@nedoz.com",
    46  		"admin@huntgear.ru",
    47  	)
    48  
    49  	opts := converter.NewOptions(0)
    50  	for _, tt := range tests {
    51  		tt := tt
    52  		if skipEmail.Contains(tt.Input) {
    53  			t.Logf("skipped %v", tt.Input)
    54  			continue
    55  		}
    56  		t.Run(tt.Input, func(t *testing.T) {
    57  			t.Parallel()
    58  			email := evmail.FromString(tt.Input)
    59  
    60  			resultValidator := validator.Validate(ev.NewInput(email))
    61  			got := d.Convert(email, resultValidator, opts)
    62  			gotPresenter := got.(DepPresentation)
    63  
    64  			sort.Strings(gotPresenter.MX.Records)
    65  			sort.Strings(tt.MX.Records)
    66  			if !reflect.DeepEqual(got, tt) {
    67  				t.Errorf("Convert()\n%#v, \n want\n%#v", got, tt)
    68  			}
    69  		})
    70  	}
    71  }