Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qawatake/fixify
A Go library for writing test fixtures in a declarative way
https://github.com/qawatake/fixify
fixture fixtures go golang testing
Last synced: 7 days ago
JSON representation
A Go library for writing test fixtures in a declarative way
- Host: GitHub
- URL: https://github.com/qawatake/fixify
- Owner: qawatake
- License: mit
- Created: 2024-07-23T03:17:39.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-25T12:40:14.000Z (5 months ago)
- Last Synced: 2024-10-29T13:59:52.428Z (about 2 months ago)
- Topics: fixture, fixtures, go, golang, testing
- Language: Go
- Homepage: https://pkg.go.dev/github.com/qawatake/fixify
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fixify
[![Go Reference](https://pkg.go.dev/badge/github.com/qawatake/fixify.svg)](https://pkg.go.dev/github.com/qawatake/fixify)
[![test](https://github.com/qawatake/fixify/actions/workflows/test.yaml/badge.svg)](https://github.com/qawatake/fixify/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/qawatake/fixify/graph/badge.svg)](https://codecov.io/gh/qawatake/fixify)`fixify` is a Go library that helps you to write test fixtures in a declarative way.
```go
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
- [Goでテストのフィクスチャをいい感じに書く](https://engineering.mercari.com/blog/entry/20220411-42fc0ba69c/)
[godoc]: https://pkg.go.dev/github.com/qawatake/fixify