resolve-internal-aliases:¶
Some libraries declare their API in an internal package and re-export it with type aliases:
package client
import "example.com/lib/internal"
type StartWorkflowOptions = internal.StartWorkflowOptions
Method signatures are written against the original type, so a mock of such an interface would import example.com/lib/internal, which Go forbids outside that module. When resolve-internal-aliases: true, mockery instead uses the public alias (client.StartWorkflowOptions).
Configuration¶
This is a root-level setting. Either every package is searched for aliases or none are.
How it works¶
While loading the packages in your config, mockery records every exported alias whose target is a named type in an internal package. Method parameters and results are then rewritten using that table, but only for types the output package is not allowed to import (so mocks generated inside the library's own tree are left alone), including types nested in pointers, slices, arrays, maps, channels, generic arguments, func signatures, struct and interface literals and unions. If several packages alias the same type, the first alias by name (e.g. example.com/lib/client.Foo) that the output package is allowed to import is used, so aliases declared in other internal packages are skipped.
This is the automatic counterpart to replace-type, which maps each type by hand.
Limitations¶
- Aliases are only found in packages that mockery loads, so list the packages that do the re-exporting.
- Type-parameter constraints of generic interfaces are not rewritten.
- Types with no public alias cause mockery to fail with an error naming the interface, method and type, because the generated code could not compile.
- Generic types that are themselves declared in an internal package (as opposed to generic types with internal arguments, which are handled) are not supported, as they would need generic aliases.