mockit

command module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: MIT Imports: 15 Imported by: 0

README

mockit generates a mock which implements a spcified interface.

Adapted from https://github.com/josharian/impl

go get -u github.com/hamster2020/mockit

Sample usage:

$ mockit 'mock *mockReadWriter' io.ReadWriter mocks
// Code generated by mockit
// DO NOT EDIT!

package mocks

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

func NewMockReadWriter() *mockReadWriter {
	return &mockReadWriter{}
}

func (mock *mockReadWriter) Read func(p []byte) (n int, err error) {
	return mock.Read(p)
}

func (mock *mockReadWriter) Write func(p []byte) (n int, err error) {
	return mock.Write(p)
}

ou can also override any mock method return value to a hardcoded value:

$ mockit 'mock *mockReadWriter' io.ReadWriter mocks "Read:0, nil"
// Code generated by mockit.
// DO NOT EDIT!
package mocks

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

func NewMockReadWriter() *mockReadWriter {
	return &mockReadWriter{}
}

func (mock *mockReadWriter) Read(p []byte) (n int, err error) {
	return 0, nil
}

func (mock *mockReadWriter) Write(p []byte) (n int, err error) {
	return mock.WriteFunc(p)
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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