https://github.com/pinzolo/mongotest
Testing helper for using MongoDB.
https://github.com/pinzolo/mongotest
fixtures golang mongodb testing
Last synced: 4 months ago
JSON representation
Testing helper for using MongoDB.
- Host: GitHub
- URL: https://github.com/pinzolo/mongotest
- Owner: pinzolo
- License: mit
- Created: 2019-09-01T15:48:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-19T00:47:19.000Z (about 2 years ago)
- Last Synced: 2025-05-07T11:53:26.860Z (5 months ago)
- Topics: fixtures, golang, mongodb, testing
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongotest
[](https://github.com/pinzolo/mongotest/actions/workflows/test.yml)
[](https://coveralls.io/github/pinzolo/mongotest?branch=master)
[](https://goreportcard.com/report/github.com/pinzolo/mongotest)
[](https://godoc.org/github.com/pinzolo/mongotest)
[](https://raw.githubusercontent.com/pinzolo/mongotest/master/LICENSE)## Description
mongotest is testing helper for using MongoDB.
## Example
```go
package mainimport (
"fmt""github.com/pinzolo/mongotest"
)func main() {
mongotest.Configure(mongotest.Config{
URL: "mongodb://root:password@127.0.0.1:27017",
Database: "mongotest",
FixtureRootDir: "testdata",
FixtureFormat: mongotest.FixtureFormatJSON,
PreInsertFuncs: []mongotest.PreInsertFunc{
mongotest.SimpleConvertTime("users", "created_at"),
},
})// 1. Read testdata/json/admin_users.json and testdata/json/foo_users.json
// 2. Merge read data
// 3. Drop collection and insert read data
err := mongotest.UseFixture("json/admin_users", "json/foo_users")
if err != nil {
panic(err)
}// Count is helper function.
// mongotest has some useful helper functions.
n, err := mongotest.Count("users")
if err != nil {
panic(err)
}
fmt.Println(n)
}
```## Install
```bash
$ go get github.com/pinzolo/mongotest
```## Contribution
1. Fork ([https://github.com/pinzolo/mongotest/fork](https://github.com/pinzolo/mongotest/fork))
1. Create a feature branch
1. Commit your changes
1. Rebase your local changes against the master branch
1. Run test suite with the `go test ./...` command and confirm that it passes
1. Run `gofmt -s`
1. Create a new Pull Request## Author
[pinzolo](https://github.com/pinzolo)