Documentation
¶
Index ¶
- type Config
- type Fabricator
- func (f Fabricator) Fabricate(traitNames ...string) interface{}
- func (f Fabricator) Field(fieldName string, generator FieldGenerator) Fabricator
- func (f Fabricator) Fields(fieldNames []string, generator FieldGenerator) Fabricator
- func (f Fabricator) Register(registry *Registry) Fabricator
- func (f Fabricator) Trait(traitName string) Trait
- func (f Fabricator) With(newTemplate interface{}) Fabricator
- func (f Fabricator) WithConfig(config *Config) Fabricator
- func (f Fabricator) ZeroFields(omitFieldNames ...string) Fabricator
- type FieldGenerator
- type Registry
- type Session
- type Trait
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DefaultGeneratorsEnabled bool
DefaultSliceLength int
DefaultMapSize int
DefaultStringLength int
GeneratePtrs bool
MaxRecursiveStructDepth int
}
A Config defines certain behaviors of a Fabricator
DefaultGeneratorsEnabled: Whether default generators will be used for literals DefaultSliceLength: Default length of generated slices DefaultMapSize: Default size of generated maps DefaultStringLength: Default length of generated strings GeneratePtrs: Whether ptrs should be generated by default MaxRecursiveStructDepth: When a struct has a field that's a ptr to its own type, how deep it should generate
type Fabricator ¶
type Fabricator struct {
Template interface{}
FieldGenerators map[string]FieldGenerator
Traits map[string]Trait
Registry *Registry
Config *Config
// contains filtered or unexported fields
}
A Fabricator generates structs matching the type of its Template
func Define ¶
func Define(template interface{}) Fabricator
Define returns a new Fabricator for generating structs of the same type as the provided struct
func (Fabricator) Fabricate ¶
func (f Fabricator) Fabricate(traitNames ...string) interface{}
Fabricate generates a new struct as configured by this Fabricator. Its return value should be type asserted to a pointer.
func (Fabricator) Field ¶
func (f Fabricator) Field(fieldName string, generator FieldGenerator) Fabricator
Field returns a Fabricator that includes a function for generating a particular field.
func (Fabricator) Fields ¶
func (f Fabricator) Fields(fieldNames []string, generator FieldGenerator) Fabricator
Fields returns a Fabricator that includes a function for generating multiple fields
func (Fabricator) Register ¶
func (f Fabricator) Register(registry *Registry) Fabricator
Register returns a Fabricator that is associated with the provided Registry.
func (Fabricator) Trait ¶
func (f Fabricator) Trait(traitName string) Trait
Trait defines a new Trait associated with this Fabricator
func (Fabricator) With ¶
func (f Fabricator) With(newTemplate interface{}) Fabricator
With returns a Fabricator that will use any non-zero values of the provided struct in the structs that it generates.
func (Fabricator) WithConfig ¶
func (f Fabricator) WithConfig(config *Config) Fabricator
WithConfig returns a Fabricator with the provided Config
func (Fabricator) ZeroFields ¶
func (f Fabricator) ZeroFields(omitFieldNames ...string) Fabricator
ZeroFields returns a Fabricator that is set to generate a set of fields to their respective zero values
type FieldGenerator ¶
type FieldGenerator func(Session) interface{}
A FieldGenerator is a function that generates a particular field using the Session
type Registry ¶
type Registry struct {
Fabricators map[string]*Fabricator
Config *Config
}
A Registry tracks multiple Fabricators, so that one Fabricator can use a different Fabricator to generate a struct type field.
func (*Registry) Add ¶
func (r *Registry) Add(fabricator *Fabricator)
Add registers an existing Fabricator to this Registry
func (*Registry) Define ¶
func (r *Registry) Define(template interface{}) Fabricator
Define returns a new Fabricator registered to this Registry
type Session ¶
type Session struct {
Struct interface{}
Config *Config
Rand *rand.Rand
// contains filtered or unexported fields
}
A Session stores data pertaining to a particular call to Fabricate, including the in-progress struct
type Trait ¶
type Trait struct {
FieldGenerators map[string]FieldGenerator
}
A Trait contains an alternate set of FieldGenerators that can be used for a particular Fabrication, in place of the Fabricator's FieldGenerators.