Documentation ¶
Index ¶
- Variables
- func DetermineOutputPackageName(interfaceFileName string, interfacePackageName string, ...) string
- type Cleanup
- type FileOutputStreamProvider
- type Generator
- func (g *Generator) Generate(ctx context.Context) error
- func (g *Generator) GenerateAll(ctx context.Context) error
- func (g *Generator) GenerateBoilerplate(boilerplate string)
- func (g *Generator) GeneratePrologue(ctx context.Context, pkg string)
- func (g *Generator) GeneratePrologueNote(note string)
- func (g *Generator) Write(w io.Writer) error
- type GeneratorConfig
- type GeneratorVisitor
- type GeneratorVisitorConfig
- type Interface
- type Method
- type NodeVisitor
- type OutputStreamProvider
- type Outputter
- type Parser
- type StdoutStreamProvider
- type TypesPackage
- type Walker
- type WalkerVisitor
Constants ¶
This section is empty.
Variables ¶
var (
ErrInfiniteLoop = fmt.Errorf("infintie loop in template variables detected")
)
var ErrNotInterface = errors.New("expression not an interface")
ErrNotInterface is returned when the given type is not an interface type.
var ErrNotSetup = errors.New("not setup")
ErrNotSetup is returned when the generator is not configured.
Functions ¶
Types ¶
type FileOutputStreamProvider ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is responsible for generating the string containing imports and the mock struct that will later be written out as file.
func NewGenerator ¶
NewGenerator builds a Generator.
func (*Generator) Generate ¶
Generate builds a string that constitutes a valid go source file containing the mock of the relevant interface.
func (*Generator) GenerateAll ¶ added in v2.21.0
func (*Generator) GenerateBoilerplate ¶ added in v2.5.0
GenerateBoilerplate adds a boilerplate text. It should be called before any other generator methods to ensure the text is on top.
func (*Generator) GeneratePrologue ¶
GeneratePrologue generates the prologue of the mock.
func (*Generator) GeneratePrologueNote ¶
GeneratePrologueNote adds a note after the prologue to the output string.
type GeneratorConfig ¶ added in v2.21.0
type GeneratorVisitor ¶
type GeneratorVisitor struct {
// contains filtered or unexported fields
}
func NewGeneratorVisitor ¶ added in v2.21.0
func NewGeneratorVisitor( config GeneratorVisitorConfig, outputStream OutputStreamProvider, dryRun bool, ) *GeneratorVisitor
type GeneratorVisitorConfig ¶ added in v2.21.0
type GeneratorVisitorConfig struct { Boilerplate string DisableVersionString bool Exported bool InPackage bool KeepTree bool Note string // The name of the output package, if InPackage is false (defaults to "mocks") PackageName string PackageNamePrefix string StructName string UnrollVariadic bool WithExpecter bool ReplaceType []string }
type Interface ¶
type Interface struct { Name string // Name of the type to be mocked. QualifiedName string // Path to the package of the target type. FileName string File *ast.File Pkg TypesPackage NamedType *types.Named IsFunction bool // If true, this instance represents a function, otherwise it's an interface. ActualInterface *types.Interface // Holds the actual interface type, in case it's an interface. SingleFunction *Method // Holds the function type information, in case it's a function type. }
Interface type represents the target type that we will generate a mock for. It could be an interface, or a function type. Function type emulates: an interface it has 1 method with the function signature and a general name, e.g. "Execute".
type NodeVisitor ¶
type NodeVisitor struct {
// contains filtered or unexported fields
}
func NewNodeVisitor ¶
func NewNodeVisitor() *NodeVisitor
func (*NodeVisitor) DeclaredInterfaces ¶
func (nv *NodeVisitor) DeclaredInterfaces() []string
type OutputStreamProvider ¶
type Outputter ¶ added in v2.21.0
type Outputter struct {
// contains filtered or unexported fields
}
Outputter wraps the Generator struct. It calls the generator to create the mock implementations in-memory, then has additional logic to determine where the mock should be written to on disk.
func NewOutputter ¶ added in v2.21.0
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) Interfaces ¶
type StdoutStreamProvider ¶
type StdoutStreamProvider struct { }