mocki

command module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 16 Imported by: 0

README

go

mocki

Generates mock implementations of interfaces using go generate. See the examples directory if you want to see what the generated code looks like.

Usage

Given an inteface and method like this:

package thinger

//go:generate mocki --interface-name=SimpleI --file-name=simple.go

type Thinger interface {
    Foo(s string) string
}

func DoThingFoo(t Thinger, s string) string {
    return t.Foo(s)
}

Running go generate will create a mock you can provide like this:

mt := MockThinger{
    FooFn: func(s string) string {
        // do anything
        return "whatever"
    }
}
output := DoThingFoo(mt, "something")
// output will be "whatever"
// mt.FooCalled() == true
// mt.FooCount() == 1

It will also generate a NOOP implementation you can use like this:

output := DoThingFoo(NOOPThinger(), "something")
// output will be nil (default values for return types)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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