Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var SecureRandom = random.New(random.CryptoSeed{})
Functions ¶
func New ¶
func New[T any](opts ...Option) *T
New returns a populated entity for a given business data entity. This is primary and only used for testing. With fixtures, it become easy to create generic query objects that can be used during testing with randomly generated data.
Example ¶
package main import ( "github.com/adamluzsi/testcase/fixtures" ) func main() { type ExampleStruct struct { Name string } var _ *ExampleStruct = fixtures.New[ExampleStruct]() }
Output:
Types ¶
type Factory ¶ added in v0.42.0
type Factory struct { Random *random.Random StubContext context.Context Options []Option // contains filtered or unexported fields }
func (*Factory) RegisterType ¶ added in v0.42.0
func (f *Factory) RegisterType(T any, ff factoryFunc)
type Option ¶ added in v0.31.0
type Option interface {
// contains filtered or unexported methods
}
func SkipByTag ¶ added in v0.31.0
SkipByTag is an Option to skip a certain tag during the New function value population. If value is not provided, all matching tag will be skipped. If value or multiple value is provided, then matching tag only skipped if it matches the values.
Example ¶
package main import ( "github.com/adamluzsi/testcase/fixtures" ) func main() { type Entity struct { ID string `external-resource:"ID" json:"id"` Value string `external-resource:"something" json:"value"` } skipByTagOption := fixtures.SkipByTag("external-resource", "ID") ent := fixtures.New[Entity](skipByTagOption) _ = ent.ID // no value populated _ = ent.Value // value populated }
Output:
Click to show internal directories.
Click to hide internal directories.