Skip to content

pinzolo/mongotest

Repository files navigation

mongotest

Test Coverage Status Go Report Card Godoc license

Description

mongotest is testing helper for using MongoDB.

Example

package main

import (
	"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

$ go get github.com/pinzolo/mongotest

Contribution

  1. Fork (https://github.com/pinzolo/mongotest/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create a new Pull Request

Author

pinzolo