Fakes should be random.
func TestGood(t *testing.T) {
t.Parallel()
faketest.AssertEachFieldIsRandom(t, Good) // OK
}
func TestBad(t *testing.T) {
t.Parallel()
faketest.AssertEachFieldIsRandom(t, Bad) // "Book.Name is not random"
}
type Book struct {
ID int64
Name string
}
func Good() *Book {
return &Book{
ID: rand.Int64(),
Name: []string{"Macbeth", "Hamlet", "Othello"}[rand.IntN(3)],
}
}
func Bad() *Book {
return &Book{
ID: rand.Int64(),
Name: "Fixed",
}
}