when generating the mocks (no matter if use-experimental-model-gen or not) this is the result:
// Code generated by pegomock. DO NOT EDIT.
// Source: bugmultiname.go
package pkg_test
import (
pegomock "github.com/petergtz/pegomock"
"reflect"
"time"
)
type MockMyFirstInterface struct {
fail func(message string, callerSkip ...int)
}
func NewMockMyFirstInterface(options ...pegomock.Option) *MockMyFirstInterface {
mock := &MockMyFirstInterface{}
for _, option := range options {
option.Apply(mock)
}
return mock
}
func (mock *MockMyFirstInterface) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockMyFirstInterface) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockMyFirstInterface) doSomethingCool() {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockMyFirstInterface().")
}
params := []pegomock.Param{}
pegomock.GetGenericMockFrom(mock).Invoke("doSomethingCool", params, []reflect.Type{})
}
...
type MockMyFirstInterface struct {
fail func(message string, callerSkip ...int)
}
func NewMockMyFirstInterface(options ...pegomock.Option) *MockMyFirstInterface {
mock := &MockMyFirstInterface{}
for _, option := range options {
option.Apply(mock)
}
return mock
}
func (mock *MockMyFirstInterface) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockMyFirstInterface) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockMyFirstInterface) FirstStoleMyName() {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockMyFirstInterface().")
}
params := []pegomock.Param{}
pegomock.GetGenericMockFrom(mock).Invoke("FirstStoleMyName", params, []reflect.Type{})
}
...
As you can see there are not two distinct interfaces but only one MyFirstInterface. If you look closely however you'll see that the first generated mock has the MyFirstInterface methods and the second has the MySecondInterface methods.
The only wrong thing is actually the name of the type.
This bug happens when:
pegomock
on a .go file and not on an interfaceWhat happens:
The generated mocks are duplicated, and all points to the first interface type.
Example
bugmultiname.go
bugmultiname_test.go
when generating the mocks (no matter if use-experimental-model-gen or not) this is the result:
As you can see there are not two distinct interfaces but only one
MyFirstInterface
. If you look closely however you'll see that the first generated mock has theMyFirstInterface
methods and the second has theMySecondInterface
methods. The only wrong thing is actually the name of the type.Go: 1.14.1