mongoose

command module
v0.0.0-...-4921599 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2018 License: MIT Imports: 9 Imported by: 0

README

Mongoose

Build Status Go Report API

Mongoose is a tool that parses your Go source code and generates a mock implementation of every interface it finds. Mongoose can generate code for a number of mocking packages:

  • Gomuti
  • Testify
  • basic stubs (standalone code; no external package required)

How to use

Use go get to place the mongoose binary under $GOPATH/bin:

$ go get github.com/xeger/mongoose
Generate your mocks

Run mongoose and pass it the name of one or more directories that contain Go sources. If you are working on package example/mockitup:

$ cd ~/go/src/example/mockitup
$ mongoose .

By default, mocks use the Gomuti package to record and play back method calls. For information on Testify and other supported mocking toolkits, skip to Alternative mocking packages below.

Use the -r flag to recurse into all subpackages and generate mocks in parallel.

$ cd ~/go/src/gigantic/project
$ mongoose -r commerce services util
Write your tests

Consult the Gomuti documentation for extensive examples. As a cheat sheet:

import (
  . "github.com/onsi/ginkgo"
  . "github.com/xeger/gomuti"
)

var _ = Describe("stuff", func() {
  It("works", func() {
    // mongoose has generated this type with one method:
    //   Add(l, r int64) int64
    adder := MockAdder{}
    Allow(adder).Call("Add").With(5,5).Return(10)
    Allow(adder).Call("Add").With(10,5).Return(15)
    Allow(adder).Call("Add").With(BeNumerically(">", 2**31-1),Anything()).Panic()

    result := subject.Multiply(3,5))
    Expect(adder).To(HaveCall("Add").Times(2))
    Expect(result).To(Equal(15))    

    Expect(func() {
      subject.Multiply(2**32, 2)
    }).To(Panic())
  })
})

Alternative mocking packages

Testify

TODO - testify docs

$ mongoose -mock=testify somepkg

Mongoose follows the filesystem conventions of testify's mockery tool; each mock is placed in its own file in the same directory as the mocked interface.

Plain stubs

WARNING: not implemented yet.

Mongoose could be capable of generating standalone stubs in the style of counterfeiter: https://github.com/maxbrunsfeld/counterfeiter

It would also be nice if Mongoose's standalones could function as stubs.

TODO - docs

How to get help

Open an issue and explain your problem, steps to reproduce, and your ideal solution (if known).

How to contribute

Fork the xeger/mongoose repository on GitHub; make your changes; open a pull request.

Documentation

Overview

Package main implements the Mongoose CLI tool. For usage information, see the README: https://github.com/xeger/mongoose

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL