Skip to content

qawatake/fixify

Repository files navigation

fixify

Go Reference test codecov

fixify is a Go library that helps you to write test fixtures in a declarative way.

func TestRun(t *testing.T) {
	// specify how to connect models in a declarative way.
	f := fixify.New(t,
		Company().With(
			Department("finance").With(
				Employee(),
				Employee(),
			),
			Department("sales").With(
				Employee(),
				Employee(),
				Employee(),
			),
		),
	)
	// Apply resolves the dependencies and applies a visitor to each model.
	f.Apply(setter)
	// finally, run the test!
}

// Department is a fixture for model.Department.
func Department(name string) *fixify.Model[model.Department] {
	d := &model.Department{
		Name: name,
	}
	return fixify.NewModel(d,
		// specify how to connect a department to a company.
		fixify.ConnectorFunc(func(_ testing.TB, department *model.Department, company *model.Company) {
			department.CompanyID = company.ID
		}),
	)
}

For more examples, please refer to the godoc.

References

About

A Go library for writing test fixtures in a declarative way

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published