Suhas Karanth 4638a53893
No variadic return types (#126)
While extracting the method and parameters from the method signature,
only check and apply the variadic flag for the input parameters and not
for the return arguments.

Issue details:

For an interface with variadic arguments and slice return type, moq was
generating an invalid mock:

	type I interface {
		Func(params ...interface{}) []byte
	}

	// ...
	type IMock struct {
		// FuncFunc mocks the Func method.
		FuncFunc func(params ...interface{}) ...byte

		// calls tracks calls to the methods.
		calls struct {
			// Func holds details about calls to the Func method.
			Func []struct {
				// Params is the params argument value.
				Params []interface{}
			}
		}
	}

On attempting to generate the mock in such an instance, the command
would fail on the formatting step:

	m.Mock: go/format: 35:30: expected ';', found '...' (and 3 more errors)

See https://github.com/matryer/moq/issues/124,
https://github.com/matryer/moq/pull/125.
2020-06-07 18:15:40 +05:30

77 lines
1.7 KiB
Go

// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package variadic
import (
"sync"
)
var (
lockEchoerMockEcho sync.RWMutex
)
// Ensure, that EchoerMock does implement Echoer.
// If this is not the case, regenerate this file with moq.
var _ Echoer = &EchoerMock{}
// EchoerMock is a mock implementation of Echoer.
//
// func TestSomethingThatUsesEchoer(t *testing.T) {
//
// // make and configure a mocked Echoer
// mockedEchoer := &EchoerMock{
// EchoFunc: func(ss ...string) []string {
// panic("mock out the Echo method")
// },
// }
//
// // use mockedEchoer in code that requires Echoer
// // and then make assertions.
//
// }
type EchoerMock struct {
// EchoFunc mocks the Echo method.
EchoFunc func(ss ...string) []string
// calls tracks calls to the methods.
calls struct {
// Echo holds details about calls to the Echo method.
Echo []struct {
// Ss is the ss argument value.
Ss []string
}
}
}
// Echo calls EchoFunc.
func (mock *EchoerMock) Echo(ss ...string) []string {
if mock.EchoFunc == nil {
panic("EchoerMock.EchoFunc: method is nil but Echoer.Echo was just called")
}
callInfo := struct {
Ss []string
}{
Ss: ss,
}
lockEchoerMockEcho.Lock()
mock.calls.Echo = append(mock.calls.Echo, callInfo)
lockEchoerMockEcho.Unlock()
return mock.EchoFunc(ss...)
}
// EchoCalls gets all the calls that were made to Echo.
// Check the length with:
// len(mockedEchoer.EchoCalls())
func (mock *EchoerMock) EchoCalls() []struct {
Ss []string
} {
var calls []struct {
Ss []string
}
lockEchoerMockEcho.RLock()
calls = mock.calls.Echo
lockEchoerMockEcho.RUnlock()
return calls
}