Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

gory

Build Status Coverage Status GoDoc

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

About

Factories for your Go structs. Think factory_girl.

Resources

License

Releases

No releases published

Packages

No packages published

Languages