Documentation
¶
Overview ¶
Package generator generates Moqueries mocks
Index ¶
- Variables
- func Generate(reqs ...GenerateRequest) error
- func GenerateWithTypeCache(cache TypeCache, req GenerateRequest) error
- type Converter
- func (c *Converter) AssertMethod() (*dst.FuncDecl, error)
- func (c *Converter) BaseDecls() ([]dst.Decl, error)
- func (c *Converter) FuncClosure(fn Func) (*dst.FuncDecl, error)
- func (c *Converter) IsolationAccessor(suffix, fnName string) (*dst.FuncDecl, error)
- func (c *Converter) MethodStructs(fn Func) ([]dst.Decl, error)
- func (c *Converter) MockMethod(fn Func) (*dst.FuncDecl, error)
- func (c *Converter) MockStructs() ([]dst.Decl, error)
- func (c *Converter) NewFunc() (*dst.FuncDecl, error)
- func (c *Converter) RecorderMethods(fn Func) ([]dst.Decl, error)
- func (c *Converter) ResetMethod() (*dst.FuncDecl, error)
- type Converterer
- type Func
- type GenerateRequest
- type GetwdFunc
- type MoqGenerator
- type MoqResponse
- type NewConverterFunc
- type Type
- type TypeCache
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidConfig is returned when configuration values are invalid or // conflict with each other ErrInvalidConfig = errors.New("invalid configuration") // ErrUnknownFieldType is returned when a param or result list has an // unknown expression ErrUnknownFieldType = errors.New("unknown field type") )
var ErrNonExported = errors.New("non-exported types")
ErrNonExported is returned by Generate when ExcludeNonExported is set to true resulting in an empty mock.
Functions ¶
func GenerateWithTypeCache ¶
func GenerateWithTypeCache(cache TypeCache, req GenerateRequest) error
GenerateWithTypeCache generates a single moq using the provided type cache. This function is exposed for use in bulk operations that have already loaded a type.
Types ¶
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter converts various interface and function types to AST structs to build a moq
func NewConverter ¶
NewConverter creates a new Converter
func (*Converter) AssertMethod ¶
AssertMethod generates a method to assert all expectations are met
func (*Converter) BaseDecls ¶
BaseDecls generates the base declarations used to store the moq's state and establish the type
func (*Converter) FuncClosure ¶
FuncClosure generates a mock implementation of function type wrapped in a closure
func (*Converter) IsolationAccessor ¶
IsolationAccessor generates a function to access an isolation interface
func (*Converter) MethodStructs ¶
MethodStructs generates a structure for storing a set of parameters or a set of results for a method invocation of a mock
func (*Converter) MockMethod ¶
MockMethod generates a mock implementation of a method
func (*Converter) MockStructs ¶ added in v0.28.0
MockStructs generates several structs used to isolate functionality for the moq
func (*Converter) RecorderMethods ¶
RecorderMethods generates a recorder implementation of a method and associated return method
type Converterer ¶
type Converterer interface {
BaseDecls() (baseDecls []dst.Decl, err error)
MockStructs() (structDecls []dst.Decl, err error)
MethodStructs(fn Func) (structDecls []dst.Decl, err error)
NewFunc() (funcDecl *dst.FuncDecl, err error)
IsolationAccessor(suffix, fnName string) (funcDecl *dst.FuncDecl, err error)
FuncClosure(fn Func) (funcDecl *dst.FuncDecl, err error)
MockMethod(fn Func) (funcDecl *dst.FuncDecl, err error)
RecorderMethods(fn Func) (funcDecls []dst.Decl, err error)
ResetMethod() (funcDecl *dst.FuncDecl, err error)
AssertMethod() (funcDecl *dst.FuncDecl, err error)
}
Converterer is the interface used by MoqGenerator to invoke a Converter
type GenerateRequest ¶
type GenerateRequest struct {
Types []string `json:"types"`
Export bool `json:"export"`
Destination string `json:"destination"`
DestinationDir string `json:"destination-dir"`
Package string `json:"package"`
Import string `json:"import"`
TestImport bool `json:"test-import"`
// WorkingDir is the current working directory. Optional, in which case
// os.Getwd is used. Useful in cases where a request is serialized then
// rerun in bulk processing from a different working directory. WorkingDir
// is used for relative-path imports and relative path destination
// files/directories.
WorkingDir string `json:"working-dir"`
// ExcludeNonExported causes the generator to exclude non-exported types
// from the generated mock. This includes possibly returning ErrNonExported
// if after exclusion, nothing is left to be written as a mock.
ExcludeNonExported bool `json:"exclude-non-exported"`
}
GenerateRequest contains all the parameters needed to call Generate
type MoqGenerator ¶
type MoqGenerator struct {
// contains filtered or unexported fields
}
MoqGenerator generates moqs
func New ¶
func New( typeCache TypeCache, getwdFn GetwdFunc, newConverterFn NewConverterFunc, ) *MoqGenerator
New returns a new MoqGenerator
func (*MoqGenerator) Generate ¶
func (g *MoqGenerator) Generate(req GenerateRequest) (MoqResponse, error)
Generate generates moqs for the given types in the given destination package
type MoqResponse ¶
MoqResponse contains the results of generating a mock
type NewConverterFunc ¶
type NewConverterFunc func(typ Type, export bool) Converterer
NewConverterFunc creates a new converter for a specific type
type TypeCache ¶
type TypeCache interface {
Type(id dst.Ident, contextPkg string, testImport bool) (ast.TypeInfo, error)
IsComparable(expr dst.Expr, parentType ast.TypeInfo) (bool, error)
IsDefaultComparable(expr dst.Expr, parentType ast.TypeInfo) (bool, error)
FindPackage(dir string) (string, error)
}
TypeCache defines the interface to the Cache type
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testmoqs contains multiple test mocks and adaptors for use in unit testing
|
Package testmoqs contains multiple test mocks and adaptors for use in unit testing |
|
other
Package other contains multiple test types for use in unit testing
|
Package other contains multiple test types for use in unit testing |