Fixtures framework for Go tests.
go get github.com/orsinium-labs/fixieCreate a fixture:
func withUser(c fixie.C) User {
return User{}
}Create a registry and register all fixtures:
var fixtures = fixie.NewRegistry()
func init() {
fixie.Register(fixtures, withUser)
}In tests, create a fixie context:
func TestUser(t *testing.T) {
c := fixie.NewC(t, fixtures)
// ...
}Now that you have a testing context, you can access values:
user := fixie.Get[User](c)The first time you call it, fixie.Get will find a fixture that produces a value of the given type, call it, and cache and return the result. On subsequent calls, the cached value will be used. The cache is local to the context, so it's safe to use with t.Parallel.
The best part is that you can access values from other fixtures as well:
func withAdmin(c fixie.C) Admin {
user := fixie.Get[User](c)
return Admin{User: user}
}