| 1 |
package test |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/icrowley/fake" |
| 5 |
|
| 6 |
"testing" |
| 7 |
) |
| 8 |
|
| 9 |
func TestSetLang(t *testing.T) { |
| 10 |
err := fake.SetLang("ru") |
| 11 |
if err != nil { |
| 12 |
t.Error("SetLang should successfully set lang") |
| 13 |
} |
| 14 |
|
| 15 |
err = fake.SetLang("sd") |
| 16 |
if err == nil { |
| 17 |
t.Error("SetLang with nonexistent lang should return error") |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
func TestFakerRuWithoutCallback(t *testing.T) { |
| 22 |
fake.SetLang("ru") |
| 23 |
fake.EnFallback(false) |
| 24 |
brand := fake.Brand() |
| 25 |
if brand != "" { |
| 26 |
t.Error("Fake call with no samples should return blank string") |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
func TestFakerRuWithCallback(t *testing.T) { |
| 31 |
fake.SetLang("ru") |
| 32 |
fake.EnFallback(true) |
| 33 |
brand := fake.Brand() |
| 34 |
if brand == "" { |
| 35 |
t.Error("Fake call for name with no samples with callback should not return blank string") |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
func TestConcurrentSafety(t *testing.T) { |
| 42 |
workerCount := 10 |
| 43 |
doneChan := make(chan struct{}) |
| 44 |
|
| 45 |
for i := 0; i < workerCount; i++ { |
| 46 |
go func() { |
| 47 |
for j := 0; j < 1000; j++ { |
| 48 |
fake.FirstName() |
| 49 |
fake.LastName() |
| 50 |
fake.Gender() |
| 51 |
fake.FullName() |
| 52 |
fake.Day() |
| 53 |
fake.Country() |
| 54 |
fake.Company() |
| 55 |
fake.Industry() |
| 56 |
fake.Street() |
| 57 |
} |
| 58 |
doneChan <- struct{}{} |
| 59 |
}() |
| 60 |
} |
| 61 |
|
| 62 |
for i := 0; i < workerCount; i++ { |
| 63 |
<-doneChan |
| 64 |
} |
| 65 |
} |