All Projects → modocache → Gory

modocache / Gory

Licence: mit
Factories for your Go structs. Think factory_girl.

Programming Languages

go
31211 projects - #10 most used programming language

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-%[email protected]", 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].