-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
faker - updated lock usage, updated seed usage.
- Loading branch information
Showing
2 changed files
with
95 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,11 @@ package gofakeit | |
|
||
import ( | ||
"fmt" | ||
"math/rand/v2" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/brianvoe/gofakeit/v6/source" | ||
) | ||
|
||
func TestSeed(t *testing.T) { | ||
// Test crypto that has no parameters in Seed | ||
GlobalFaker = New(0) | ||
Seed(11) | ||
|
||
// Will panic if Seed couldn't be called | ||
t.Fatal("Seed failed") | ||
} | ||
|
||
func Example() { | ||
Seed(11) | ||
|
||
|
@@ -50,29 +40,59 @@ func Example() { | |
|
||
func ExampleNew() { | ||
// Get new faker with default settings | ||
fake := New(0) | ||
|
||
// or | ||
|
||
// Create new faker with ChaCha8 | ||
chacha := source.NewChaCha8([32]byte{5, 4, 3, 2, 1, 0}, true) | ||
fake = NewFaker(chacha) | ||
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: Markus Moen | ||
// Email: [email protected] | ||
// Phone: 9948995369 | ||
// 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 | ||
cryptoFaker := source.NewCrypto(true) | ||
GlobalFaker = NewFaker(cryptoFaker) | ||
crypto := rand.NewPCG(11, 11) | ||
GlobalFaker = NewFaker(crypto, true) | ||
|
||
// Test a simple function | ||
name := Name() | ||
|