Skip to content

Commit

Permalink
Add test for unique email
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed May 25, 2019
1 parent 8df4206 commit b3298b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"syreclabs.com/go/faker"
)

var fakeEmail = faker.Internet().Email

type Provider struct{
providedUniqueEmails map[string]int
}
Expand Down Expand Up @@ -33,7 +35,7 @@ func (p Provider) Get(s string) string {
case "email":
return faker.Internet().Email()
case "unique_email":
new := faker.Internet().Email()
new := fakeEmail()

_, exists := p.providedUniqueEmails[new]
if !exists {
Expand Down
20 changes: 20 additions & 0 deletions src/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dbanon

import (
"testing"
)

func TestGet(t *testing.T) {
fakeEmail = func() string {
return "bob@example.com"
}

provider := NewProvider()
_ = provider.Get("unique_email")

r1 := provider.Get("unique_email")
if r1 != "1bob@example.com" {
t.Errorf("Got %s wanted 1bob@example.com", r1)
}

}

0 comments on commit b3298b9

Please sign in to comment.