Description
In one of our projects I have an, admittedly quite exotic, edge-case where we're mocking an interface from another package and the transient imports all have the same package name at the end of the path. The conflict resolve mechanism for aliases doesn't work in this case, as it only looks at 2 conflicting packages at a time.
To reproduce it requires at least 4 imports and you need to be mocking an interface from another package, so not setting unique aliases yourself.
Mocked Interface
package transientimport
import (
"github.com/matryer/moq/pkg/moq/testpackages/transientimport/base"
)
type Transient = base.Transient
Original Interface
package base
import (
four "github.com/matryer/moq/pkg/moq/testpackages/transientimport/four/app/v1"
one "github.com/matryer/moq/pkg/moq/testpackages/transientimport/one/v1"
three "github.com/matryer/moq/pkg/moq/testpackages/transientimport/three/v1"
two "github.com/matryer/moq/pkg/moq/testpackages/transientimport/two/app/v1"
)
type Transient interface {
DoSomething(one.One, two.Two, three.Three, four.Four)
}
The origin is that we're using an interface from the k8s.io/client-go/kubernetes
package and want to use mocks of that interface in our tests.
I put together a test case and possible solution here:
https://github.com/cldmstr/moq/tree/unique-import-aliases
Activity