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)
}