gory
Factories for your Go structs. Think factory_girl.
Usage
To install, just go get
it:
go get github.com/modocache/gory
gory is fully documented, but below are some examples to get you started.
Defining Factories
Define factories that may be used during any test. Works great in a global setup hook.
gory.Define("user", User{}, func(factory gory.Factory) {
factory["FirstName"] = "John"
factory["LastName"] = "Doe"
factory["Admin"] = false
// 'n' in email is incremented each time the factory is built
factory["Email"] = gory.Sequence(func(n int) interface{} {
return fmt.Sprintf("john-doe-%d@example.com", n)
})
// time.Now() is evaluated when the factory is built
factory["Created"] = gory.Lazy(func() interface{} {
return time.Now()
})
})
See gory_suite_test.go
for more examples of defining factories.
Using Factories
john := gory.Build("user").(*User)
fmt.Println(john.FirstName) // "John"
jane := gory.BuildWithParams("user", gory.Factory{
"FirstName": "Jane"
}).(*User)
fmt.Println(jane.FirstName) // "Jane"
See gory_test.go
for more examples of using factories.
Coming Soon
- Aliases
- Dependent attributes
- Transient attributes
- Associations
- Inheritance
- Traits
- Callbacks
- ...and pretty much anything else factory_girl can do.