mongotest is testing helper for using MongoDB.
package main
import (
"fmt"
"github.com/pinzolo/mongotest"
)
func main() {
mongotest.Configure(mongotest.Config{
URL: "mongodb://root:[email protected]: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)
}
$ go get github.com/pinzolo/mongotest
- Fork (https://github.com/pinzolo/mongotest/fork)
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
go test ./...
command and confirm that it passes - Run
gofmt -s
- Create a new Pull Request