forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faker_test.go
122 lines (100 loc) · 2.56 KB
/
faker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package gofakeit
import (
"fmt"
"math/rand/v2"
"sync"
"testing"
)
func Example() {
Seed(11)
fmt.Println("Name:", Name())
fmt.Println("Email:", Email())
fmt.Println("Phone:", Phone())
fmt.Println("Address:", Address().Address)
fmt.Println("BS:", BS())
fmt.Println("Beer Name:", BeerName())
fmt.Println("Color:", Color())
fmt.Println("Company:", Company())
fmt.Println("Credit Card:", CreditCardNumber(nil))
fmt.Println("Hacker Phrase:", HackerPhrase())
fmt.Println("Job Title:", JobTitle())
fmt.Println("Password:", Password(true, true, true, true, false, 32))
// Output: Name: Sonny Stiedemann
// Email: [email protected]
// Phone: 7598907999
// Address: 4737 Port Hillstown, Santa Ana, Alabama 41026
// BS: enable
// Beer Name: Chocolate St
// Color: Turquoise
// Company: Boundless
// Credit Card: 6282690620525711
// Hacker Phrase: Try to bundle the PNG firewall, maybe it will deconstruct the open-source bandwidth!
// Job Title: Assistant
// Password: Nyf8p8ka1Kvgn...3H*.w7j01yM1vkc2
}
func ExampleNew() {
// Get new faker with default settings
fake := New(11)
// All global functions are also available in the structs methods
fmt.Println("Name:", fake.Name())
fmt.Println("Email:", fake.Email())
fmt.Println("Phone:", fake.Phone())
// Output:
// Name: Sonny Stiedemann
// Email: [email protected]
// Phone: 7598907999
}
func ExampleNewFaker() {
// Create new faker with ChaCha8, cryptographically secure
chacha := rand.NewChaCha8([32]byte{5, 4, 3, 2, 1, 0})
fake := NewFaker(chacha, true)
// or
// Create new faker with PCG, pseudo-random
pcg := rand.NewPCG(0, 0)
fake = NewFaker(pcg, false)
fmt.Println("Name:", fake.Name())
// Output:
// Name: Damian Pagac
}
func TestSeed(t *testing.T) {
// Test crypto that has no parameters in Seed
GlobalFaker = New(11)
// Test a simple function
name := Name()
// Seed
err := Seed(11)
if err != nil {
t.Error(err)
}
// Make sure name is the same
if name != Name() {
t.Error("Name was different after seed")
}
}
func TestSetGlobalFaker(t *testing.T) {
// Set global to crypto
crypto := rand.NewPCG(11, 11)
GlobalFaker = NewFaker(crypto, true)
// Test a simple function
name := Name()
if name == "" {
t.Error("Name was empty")
}
// Set global back to default
GlobalFaker = New(0)
}
func TestConcurrency(t *testing.T) {
var setupComplete sync.WaitGroup
setupComplete.Add(1)
var wg sync.WaitGroup
for i := 0; i < 1000; i++ {
wg.Add(1)
go func() {
setupComplete.Wait()
Paragraph(1, 5, 20, " ")
wg.Done()
}()
}
setupComplete.Done()
wg.Wait()
}