Skip to content

theoden9014/simplemock

Repository files navigation

simplemock

Go Report Card

This is a code generator for mock from interfaces in Go.

Installation

go get -u github.com/theoden9014/simplemock/cmd/simplemockgen

Usage

Usage: simplemockgen [options...] path1, path2, ...
  -out string
    	output file, default output to stdout
  -pkgname string
    	output package name for mock

Example

// example.go
package example

type Reader interface {
	Read(p []byte) (n int, err error)
}
$ simplemockgen ./example.go

Then the following code will be generated.

package example

type ReaderMock struct {
	ReadFunc func(p []byte) (n int, err error)
}

func (m *ReaderMock) Read(p []byte) (n int, err error) {
	if m.ReadFunc != nil {
		return m.ReadFunc(p)
	}
	return 0, nil
}

About

This is a code generator for mock from interfaces in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages