@@ -75,32 +75,32 @@ func TestIsValidSocialErrorResponses(t *testing.T) {
75
75
var err error
76
76
77
77
testSocialNumber := "" //Empty
78
- if _ , err = IsValidSocial (testSocialNumber ); err .Error () != "social is empty" {
78
+ if _ , err = IsValidSocial (testSocialNumber ); err != nil && err .Error () != "social is empty" {
79
79
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
80
80
}
81
81
82
82
testSocialNumber = "2123" //Not long enough
83
- if _ , err = IsValidSocial (testSocialNumber ); err .Error () != "social is not nine digits in length" {
83
+ if _ , err = IsValidSocial (testSocialNumber ); err != nil && err .Error () != "social is not nine digits in length" {
84
84
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
85
85
}
86
86
87
87
testSocialNumber = "000-00-0000" //All zeros
88
- if _ , err = IsValidSocial (testSocialNumber ); err .Error () != "social section was found invalid (cannot be 000 or 666)" {
88
+ if _ , err = IsValidSocial (testSocialNumber ); err != nil && err .Error () != "social section was found invalid (cannot be 000 or 666)" {
89
89
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
90
90
}
91
91
92
92
testSocialNumber = "1234-1-2342" //Invalid Pattern
93
- if _ , err = IsValidSocial (testSocialNumber ); err .Error () != "social does not match the regex pattern" {
93
+ if _ , err = IsValidSocial (testSocialNumber ); err != nil && err .Error () != "social does not match the regex pattern" {
94
94
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
95
95
}
96
96
97
97
testSocialNumber = "000-00-2345" //Invalid section
98
- if _ , err = IsValidSocial (testSocialNumber ); err .Error () != "social section was found invalid (cannot be 000 or 666)" {
98
+ if _ , err = IsValidSocial (testSocialNumber ); err != nil && err .Error () != "social section was found invalid (cannot be 000 or 666)" {
99
99
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
100
100
}
101
101
102
102
for _ , ssn := range blacklistedSocials { //Blacklisted
103
- if _ , err = IsValidSocial (ssn ); err .Error () != "social was found to be blacklisted" {
103
+ if _ , err = IsValidSocial (ssn ); err != nil && err .Error () != "social was found to be blacklisted" {
104
104
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
105
105
}
106
106
}
@@ -322,33 +322,33 @@ func TestIsValidEmailErrorResponses(t *testing.T) {
322
322
var err error
323
323
324
324
email := "test"
325
- if _ , err = IsValidEmail (email , false ); err .Error () != "email length is invalid" {
325
+ if _ , err = IsValidEmail (email , false ); err != nil && err .Error () != "email length is invalid" {
326
326
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
327
327
}
328
328
329
329
email = "test@"
330
- if _ , err = IsValidEmail (email , false ); err .Error () != "email is not a valid address format" {
330
+ if _ , err = IsValidEmail (email , false ); err != nil && err .Error () != "email is not a valid address format" {
331
331
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
332
332
}
333
333
334
334
email = "test.some"
335
- if _ , err = IsValidEmail (email , false ); err .Error () != "email is not a valid address format" {
335
+ if _ , err = IsValidEmail (email , false ); err != nil && err .Error () != "email is not a valid address format" {
336
336
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
337
337
}
338
338
339
339
email = "@this.com"
340
- if _ , err = IsValidEmail (email , false ); err .Error () != "email is not a valid address format" {
340
+ if _ , err = IsValidEmail (email , false ); err != nil && err .Error () != "email is not a valid address format" {
341
341
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
342
342
}
343
343
344
344
email = "1234567890123456789012345678901234567890123456789012345678901234567890@this.com"
345
- if _ , err = IsValidEmail (email , false ); err .Error () != "email length is invalid" {
345
+ if _ , err = IsValidEmail (email , false ); err != nil && err .Error () != "email length is invalid" {
346
346
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
347
347
}
348
348
349
349
//Test all blacklisted hosts and errors
350
350
for _ , host := range blacklistedDomains {
351
- if _ , err = IsValidEmail ("someone@" + host , false ); err .Error () != "email domain is not accepted" {
351
+ if _ , err = IsValidEmail ("someone@" + host , false ); err != nil && err .Error () != "email domain is not accepted" {
352
352
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
353
353
}
354
354
}
@@ -358,7 +358,7 @@ func TestIsValidEmailErrorResponses(t *testing.T) {
358
358
359
359
//email domain invalid/cannot receive mail: lookup gmail.conn on 169.254.169.254:53: no such host
360
360
//if err.Error() != "email domain invalid/cannot receive mail: lookup gmail.conn: no such host" {
361
- if ! strings .Contains (err .Error (), "email domain invalid/cannot receive mail:" ) {
361
+ if err != nil && ! strings .Contains (err .Error (), "email domain invalid/cannot receive mail:" ) {
362
362
t .Fatal ("Error response was not as expected - Value: " + err .Error ())
363
363
}
364
364
}
@@ -397,7 +397,7 @@ func TestIsValidEnum(t *testing.T) {
397
397
testAcceptedValues := []string {"123" }
398
398
if ok , err = IsValidEnum (testEnumValue , & testAcceptedValues , false ); ok {
399
399
t .Fatal ("This should have failed - value is not found" , testEnumValue , testAcceptedValues , err )
400
- } else if err .Error () != "value " + testEnumValue + " is not allowed" {
400
+ } else if err != nil && err .Error () != "value " + testEnumValue + " is not allowed" {
401
401
t .Fatal ("error message was not as expected" , err .Error ())
402
402
}
403
403
@@ -458,7 +458,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
458
458
459
459
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
460
460
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
461
- } else if err .Error () != "country code length is invalid" {
461
+ } else if err != nil && err .Error () != "country code length is invalid" {
462
462
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
463
463
}
464
464
@@ -467,7 +467,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
467
467
468
468
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
469
469
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
470
- } else if err .Error () != "country code length is invalid" {
470
+ } else if err != nil && err .Error () != "country code length is invalid" {
471
471
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
472
472
}
473
473
@@ -476,7 +476,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
476
476
477
477
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
478
478
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
479
- } else if err .Error () != "country code 32 is not accepted" {
479
+ } else if err != nil && err .Error () != "country code 32 is not accepted" {
480
480
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
481
481
}
482
482
@@ -485,7 +485,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
485
485
486
486
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
487
487
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
488
- } else if err .Error () != "phone number length is invalid" {
488
+ } else if err != nil && err .Error () != "phone number length is invalid" {
489
489
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
490
490
}
491
491
@@ -495,7 +495,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
495
495
496
496
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
497
497
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
498
- } else if err .Error () != "phone number must be ten digits" {
498
+ } else if err != nil && err .Error () != "phone number must be ten digits" {
499
499
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
500
500
}
501
501
@@ -505,7 +505,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
505
505
506
506
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
507
507
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
508
- } else if err .Error () != "phone number must be either eight or ten digits" {
508
+ } else if err != nil && err .Error () != "phone number must be either eight or ten digits" {
509
509
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
510
510
}
511
511
@@ -515,7 +515,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
515
515
516
516
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
517
517
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
518
- } else if err .Error () != "phone number must be ten digits" {
518
+ } else if err != nil && err .Error () != "phone number must be ten digits" {
519
519
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
520
520
}
521
521
@@ -525,7 +525,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
525
525
526
526
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
527
527
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
528
- } else if err .Error () != "phone number NPA cannot start with 1" {
528
+ } else if err != nil && err .Error () != "phone number NPA cannot start with 1" {
529
529
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
530
530
}
531
531
@@ -535,7 +535,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
535
535
536
536
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
537
537
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
538
- } else if err .Error () != "phone number NPA cannot start with 0" {
538
+ } else if err != nil && err .Error () != "phone number NPA cannot start with 0" {
539
539
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
540
540
}
541
541
@@ -545,7 +545,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
545
545
546
546
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
547
547
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
548
- } else if err .Error () != "phone number NPA cannot start with 1" {
548
+ } else if err != nil && err .Error () != "phone number NPA cannot start with 1" {
549
549
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
550
550
}
551
551
@@ -555,7 +555,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
555
555
556
556
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
557
557
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
558
- } else if err .Error () != "phone number NPA cannot start with 0" {
558
+ } else if err != nil && err .Error () != "phone number NPA cannot start with 0" {
559
559
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
560
560
}
561
561
@@ -565,7 +565,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
565
565
566
566
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
567
567
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
568
- } else if err .Error () != "phone number NPA cannot start with 555" {
568
+ } else if err != nil && err .Error () != "phone number NPA cannot start with 555" {
569
569
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
570
570
}
571
571
@@ -575,7 +575,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
575
575
576
576
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
577
577
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
578
- } else if err .Error () != "phone number NXX cannot start with 1" {
578
+ } else if err != nil && err .Error () != "phone number NXX cannot start with 1" {
579
579
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
580
580
}
581
581
@@ -585,7 +585,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
585
585
586
586
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
587
587
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
588
- } else if err .Error () != "phone number NXX cannot start with 0" {
588
+ } else if err != nil && err .Error () != "phone number NXX cannot start with 0" {
589
589
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
590
590
}
591
591
@@ -595,7 +595,7 @@ func TestIsValidPhoneNumber(t *testing.T) {
595
595
596
596
if ok , err = IsValidPhoneNumber (phone , countryCode ); ok {
597
597
t .Fatal ("This should have failed - phone is invalid for USA" , phone , countryCode , err )
598
- } else if err .Error () != "phone number NXX cannot be X11" {
598
+ } else if err != nil && err .Error () != "phone number NXX cannot be X11" {
599
599
t .Fatal ("error message was not as expected" , phone , countryCode , err .Error ())
600
600
}
601
601
0 commit comments