mockif

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 5 Imported by: 0

README

Mockif

Short for "Mocking interfaces"!

Mockif generates a mock implementation for any interfaces found in Go package provided. It skips any test files (*_test.go). For example, such interface:

type Foo interface {
	Bar(a string, b []int) error
	Baz (a fmt.Scanner, b byte) []byte  
}

will yield this test implementation:

type mockFoo struct {
	mBar func(a string, b []int) error
	mBaz func(a fmt.Scanner, b byte) []byte
}

func (fm mockFoo) Bar(a string, b []int) error {
	return fm.mBar(a, b)
}
func (fm mockFoo) Baz(a fmt.Scanner, b byte) []byte {
	return fm.mBaz(a, b)
}

Then it can be used to define the behavior of the mock implementation in vanilla Golang test suite.

For now, the func type is not supported for arguments and return parameters of methods.

Usage

mockif tool is able to process 2 positional (not named) arguments:

  1. Path to the directory that holds the package. Can be either relative or absolute:
mockif ./example
  1. Name of the file with generated implementations (mocks.go by default):
mockif ./example mocks_test.go

Installation

go install github.com/gren236/mockif@latest

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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