Skip to content

Commit

Permalink
feat(go): add AddCustomDomains
Browse files Browse the repository at this point in the history
  • Loading branch information
choznerol committed Nov 9, 2021
1 parent 4b668de commit 2a62379
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions platform/go/mail_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ func IsBlacklisted(email string) bool {

return false
}

func AddCustomDomains(domains []string) map[string]struct{} {
for _, domain := range domains {
blacklist[domain] = itemExists
}

return blacklist
}
8 changes: 8 additions & 0 deletions platform/go/mail_checker.tmpl._go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ func IsBlacklisted(email string) bool {

return false
}

func AddCustomDomains(domains []string) map[string]struct{} {
for _, domain := range domains {
blacklist[domain] = itemExists
}

return blacklist
}
60 changes: 60 additions & 0 deletions platform/go/mail_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,63 @@ func TestReturnFalseForBlacklistedDomainsAndTheirSubdomains(t *testing.T) {
}
}
}

func TestAddCustomDomains(t *testing.T) {
testCasesBefore := []struct {
email string
valid bool
}{
{
email: "foo@youtube.com",
valid: true,
},
{
email: "foo@google.com",
valid: true,
},
{
email: "ok@gmail.com",
valid: true,
},
}

for i, testCase := range testCasesBefore {
result := IsValid(testCase.email)

if result != testCase.valid {
t.Errorf("Expected result for email %s (test case %d) is %t, got %t", testCase.email, i, testCase.valid, result)
}
}

domains := []string{
"youtube.com",
"google.com",
}
AddCustomDomains(domains)

testCasesAfter := []struct {
email string
valid bool
}{
{
email: "foo@youtube.com",
valid: false,
},
{
email: "foo@google.com",
valid: false,
},
{
email: "ok@gmail.com",
valid: true,
},
}

for i, testCase := range testCasesAfter {
result := IsValid(testCase.email)

if result != testCase.valid {
t.Errorf("Expected result for email %s (test case %d) is %t, got %t", testCase.email, i, testCase.valid, result)
}
}
}

0 comments on commit 2a62379

Please sign in to comment.