Documentation
¶
Overview ¶
Package parser contains the parser for reading Go files and building the interface definitions needed to generate mocks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IncludingInterfaceFilter ¶
type IncludingInterfaceFilter struct {
InterfacesToInclude []string
}
IncludingInterfaceFilter is an InterfaceFilter that works based on an allow-list of interface names.
func (*IncludingInterfaceFilter) Include ¶
func (f *IncludingInterfaceFilter) Include(name string) bool
Include returns true if the specified interface should be mocked, false otherwise.
type InterfaceFilter ¶
type InterfaceFilter interface {
// Include indicates that the specified interface should be included in the set of interfaces
// to generate.
Include(name string) bool
}
InterfaceFilter is used to decide which interfaces mocks should be generated for.
type MethodDefinition ¶
type MethodDefinition struct {
// Name is the name of the method.
Name string
// Parameters contains the parameters passed to the method.
Parameters []ParameterDefinition
// Results contains the method results.
Results []ResultDefinition
// Comment contains any comments added to the method.
Comment string
}
MethodDefinition defines a method in an interface.
type MockedInterface ¶
type MockedInterface struct {
// Name contains the name of the interface.
Name string
// FullName contains the full name of the interface. For interfaces nested inside a struct,
// this will contain the full dot-separated path to the interface, for example `UserService.ConfigRepository`.
FullName string
// PackageName contains the name of the package that the interface belongs to.
PackageName string
// Methods contains the list of methods in the interface.
Methods []MethodDefinition
// Imports contains the list of imports required by the mocked interface.
Imports []string
}
MockedInterface represents an interface that a mock should be generated for.
func (MockedInterface) AnyMethodsHaveParameters ¶
func (i MockedInterface) AnyMethodsHaveParameters() bool
AnyMethodsHaveParameters returns true if at least one method in the interface has at least one parameter.
type ParameterDefinition ¶
type ParameterDefinition struct {
// Name is the name of the parameter.
Name string
// Type is the parameter's type.
Type string
// IsVariadic indicates that this is the variable argument to a variadic function.
IsVariadic bool
// IsNonEmptyInterface indicates that the parameter type is an interface with at least one method.
IsNonEmptyInterface bool
}
ParameterDefinition contains information about a method parameter.
type ParsedPackage ¶
type ParsedPackage struct {
// PackageDirectory is the directory containing the package source files.
PackageDirectory string
// Mocks are the mocks that were parsed from the package.
Mocks []MockedInterface
}
ParsedPackage contains the information needed to generate mocks from parsing a package.
func Parse ¶
func Parse(packageName string, directory string, filter InterfaceFilter) (*ParsedPackage, error)
Parse parses the source contained in the reader.
type ResultDefinition ¶
type ResultDefinition struct {
// Name is the name of the method result. This can be empty if the result is not named.
Name string
// Type is the type of the result.
Type string
}
ResultDefinition contains information about a method result.
Directories
¶
| Path | Synopsis |
|---|---|
|
mocks
|
|
|
interfacefilter
Code generated by Kelpie.
|
Code generated by Kelpie. |