Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
evisdrenova committed Nov 20, 2023
1 parent 39cc03b commit 009009e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 0 additions & 2 deletions worker/internal/benthos/transformers/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func GenerateDomain() (string, error) {
var result string

domain, err := transformer_utils.GenerateRandomStringWithLength(6)

if err != nil {
return "", fmt.Errorf("unable to generate random domain name")
}
Expand Down Expand Up @@ -225,7 +224,6 @@ func parseEmail(email string) ([]string, error) {

inputEmail, err := mail.ParseAddress(email)
if err != nil {

return nil, fmt.Errorf("invalid email format: %s", email)
}

Expand Down
14 changes: 11 additions & 3 deletions worker/internal/benthos/transformers/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func Test_GenerateRandomEmail(t *testing.T) {

func Test_EmailTransformerWithValue(t *testing.T) {
testVal := "[email protected]"
mapping := fmt.Sprintf(`root = emailtransformer("%s",true,true)`, testVal)
mapping := fmt.Sprintf(`root = emailtransformer(%q,true,true)`, testVal)
ex, err := bloblang.Parse(mapping)
assert.NoError(t, err)
assert.NoError(t, err, "failed to parse the email transformer")
Expand All @@ -104,7 +104,7 @@ func Test_EmailTransformerWithValue(t *testing.T) {

func Test_EmailTransformerWithEmptyValue(t *testing.T) {
testVal := ""
mapping := fmt.Sprintf(`root = emailtransformer("%s",true,true)`, testVal)
mapping := fmt.Sprintf(`root = emailtransformer(%q,true,true)`, testVal)
ex, err := bloblang.Parse(mapping)
assert.NoError(t, err)
assert.NoError(t, err, "failed to parse the email transformer")
Expand All @@ -123,7 +123,7 @@ func Test_EmailTransformerEmailParamError(t *testing.T) {
}
func Test_EmailTransformerPreserveLengthParamError(t *testing.T) {
testVal := ""
mapping := fmt.Sprintf(`root = emailtransformer("%s",true)`, testVal)
mapping := fmt.Sprintf(`root = emailtransformer(%q,true)`, testVal)
_, err := bloblang.Parse(mapping)
assert.Error(t, err, "failed to parse the email transformer, missing param")

Expand All @@ -135,6 +135,14 @@ func Test_EmailTransformerErrorParams(t *testing.T) {

}

func Test_ParseEmailError(t *testing.T) {
test := "ehiu.com"

_, err := parseEmail(test)
assert.Error(t, err)

}

func isValidEmail(email string) bool {
// Regular expression pattern for a simple email validation
emailPattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
Expand Down

0 comments on commit 009009e

Please sign in to comment.