github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/presentation/prompt-email-verification-api/dep_functional_test.go (about)

     1  package promptemailverificationapi
     2  
     3  import (
     4  	"reflect"
     5  	"sort"
     6  	"testing"
     7  
     8  	"github.com/emirpasic/gods/sets/hashset"
     9  
    10  	"github.com/go-email-validator/go-email-validator/pkg/ev"
    11  	"github.com/go-email-validator/go-email-validator/pkg/ev/evtests"
    12  	"github.com/go-email-validator/go-email-validator/pkg/presentation/converter"
    13  	"github.com/go-email-validator/go-email-validator/pkg/presentation/test"
    14  )
    15  
    16  func TestMain(m *testing.M) {
    17  	evtests.TestMain(m)
    18  }
    19  
    20  func TestDepConverter_Convert(t *testing.T) {
    21  	evtests.FunctionalSkip(t)
    22  
    23  	validator := NewDepValidator(nil)
    24  	d := NewDepConverter()
    25  	tests := make([]DepPresenterTest, 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  		// Banned on disposable domain
    31  		"sewag33689@itymail.com",
    32  		// Banned on disposable domain
    33  		"sewag33689@itymail.com",
    34  		// Banned on disposable domain
    35  		"asdasd@tradepro.net",
    36  		// Banned on disposable domain
    37  		"tvzamhkdc@emlhub.com",
    38  		// Banned
    39  		"credit@mail.ru",
    40  		// Banned
    41  		"salestrade86@hotmail.com",
    42  		// Banned
    43  		"monicaramirezrestrepo@hotmail.com",
    44  		// TODO Cannot connect from my hosts pc
    45  		"y-numata@senko.ed.jp",
    46  		"theofanisgiotis@12pm.gr",
    47  		"theofanis.giot2is@12pm.gr",
    48  		"admin@huntgear.ru",
    49  		"derduzikne@nedoz.com",
    50  	)
    51  
    52  	opts := converter.NewOptions(0)
    53  	for _, tt := range tests {
    54  		tt := tt
    55  		if skipEmail.Contains(tt.Email) {
    56  			t.Logf("skipped %v", tt.Email)
    57  			continue
    58  		}
    59  
    60  		t.Run(tt.Email, func(t *testing.T) {
    61  			t.Parallel()
    62  
    63  			email := EmailFromString(tt.Email)
    64  
    65  			resultValidator := validator.Validate(ev.NewInput(email))
    66  			got := d.Convert(email, resultValidator, opts)
    67  			gotPresenter := got.(DepPresentation)
    68  
    69  			sort.Strings(gotPresenter.MxRecords.Records)
    70  			sort.Strings(tt.Dep.MxRecords.Records)
    71  			if !reflect.DeepEqual(got, tt.Dep) {
    72  				t.Errorf("Convert()\n%#v, \n want\n%#v", got, tt.Dep)
    73  			}
    74  		})
    75  	}
    76  }
    77  
    78  // see prompt_email_verification_api/cmd/dep_test_generator/gen.go
    79  type DepPresenterTest struct {
    80  	Email string
    81  	Dep   DepPresentation
    82  }