Skip to content

Commit

Permalink
Ensure email is unique
Browse files Browse the repository at this point in the history
Ideally we'd be able to ask Faker for a unique value
but handling on our end until that feature is available:

dmgk/faker#12
  • Loading branch information
mpchadwick committed May 24, 2019
1 parent 6fb9485 commit 8df4206
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
26 changes: 13 additions & 13 deletions etc/magento2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ tables:
columns:
firstname: firstname
lastname: lastname
email: email
email: unique_email
username: username
password: password
- name: customer_entity
columns:
email: email
email: unique_email
firstname: firstname
lastname: lastname
vat_id: vat_number
- name: customer_grid_flat
columns:
name: fullname
email: email
email: unique_email
dob: date
gender: gender
taxvat: vat_number
Expand Down Expand Up @@ -47,11 +47,11 @@ tables:
vat_id: vat_number
- name: newsletter_subscriber
columns:
subscriber_email: email
subscriber_email: unique_email
subscriber_confirm_code: md5
- name: quote
columns:
customer_email: email
customer_email: unique_email
customer_prefix: title
customer_firstname: firstname
customer_middlename: firstname
Expand All @@ -62,7 +62,7 @@ tables:
remote_ip: ipv4
- name: quote_address
columns:
email: email
email: unique_email
prefix: title
firstname: firstname
lastname: lastname
Expand All @@ -89,18 +89,18 @@ tables:
billing_address: street
shipping_address: street
customer_name: fullname
customer_email: email
customer_email: unique_email
- name: sales_invoice_grid
columns:
customer_name: fullname
customer_email: email
customer_email: unique_email
billing_name: fullname
billing_address: street
shipping_address: street
- name: sales_order
columns:
customer_dob: datetime
customer_email: email
customer_email: unique_email
customer_prefix: title
customer_firstname: firstname
customer_middlename: firstname
Expand All @@ -115,7 +115,7 @@ tables:
lastname: lastname
street: street
city: city
email: email
email: unique_email
telephone: telephone
firstname: firstname
prefix: title
Expand All @@ -128,7 +128,7 @@ tables:
billing_name: fullname
billing_address: street
shipping_address: street
customer_email: email
customer_email: unique_email
cutomer_name: fullname
- name: sales_shipment_grid
columns:
Expand All @@ -137,14 +137,14 @@ tables:
shipping_address: street
billing_name: fullname
shipping_name: fullname
customer_email: email
customer_email: unique_email
- name: sendfriend_log
columns:
ip: ipv4
eav:
- name: customer
attributes:
email: email
email: unique_email
prefix: title
firstname: firstname
middlename: firstname
Expand Down
23 changes: 21 additions & 2 deletions src/provider.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package dbanon

import (
"strconv"
"strings"
"syreclabs.com/go/faker"
)

type Provider struct{}
type Provider struct{
providedUniqueEmails map[string]int
}

func NewProvider() *Provider {
p := &Provider{}
made := make(map[string]int)

p := &Provider{providedUniqueEmails: made}

return p
}
Expand All @@ -26,6 +32,19 @@ func (p Provider) Get(s string) string {
return faker.Name().FirstName() + " " + faker.Name().LastName()
case "email":
return faker.Internet().Email()
case "unique_email":
new := faker.Internet().Email()

_, exists := p.providedUniqueEmails[new]
if !exists {
p.providedUniqueEmails[new] = 0
return new
}

p.providedUniqueEmails[new]++
ret := strings.Join([]string{strconv.Itoa(p.providedUniqueEmails[new]), new}, "")

return ret
case "username":
return faker.Internet().UserName()
case "password":
Expand Down

0 comments on commit 8df4206

Please sign in to comment.