Fixtures framework for Go tests.
go get github.com/orsinium-labs/fixie
Create a fixture:
funcwithUser(c fixie.C)User {returnUser{}}Create a registry and register all fixtures:
varfixtures=fixie.NewRegistry()funcinit() {fixie.Register(fixtures,withUser)}In tests, create a fixie context:
funcTestUser(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 witht.Parallel.
The best part is that you can access values from other fixtures as well:
funcwithAdmin(c fixie.C)Admin {user:= fixie.Get[User](c)returnAdmin{User:user}}