mockery

package
Version: v0.0.0-...-6216e21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2020 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogKeyBaseDir   = "base-dir"
	LogKeyFile      = "file"
	LogKeyPath      = "path"
	LogKeyDir       = "dir"
	LogKeyInterface = "interface"
)

Variables

View Source
var ErrNotInterface = errors.New("expression not an interface")

ErrNotInterface is returned when the given type is not an interface type.

View Source
var ErrNotSetup = errors.New("not setup")

ErrNotSetup is returned when the generator is not configured.

View Source
var SemVer = "1.0.0"

SemVer is the version of mockery at build time.

Functions

This section is empty.

Types

type Cleanup

type Cleanup func() error

type FileOutputStreamProvider

type FileOutputStreamProvider struct {
	BaseDir                   string
	InPackage                 bool
	TestOnly                  bool
	Case                      string
	KeepTree                  bool
	KeepTreeOriginalDirectory string
	FileName                  string
}

func (*FileOutputStreamProvider) GetWriter

func (this *FileOutputStreamProvider) GetWriter(ctx context.Context, iface *Interface) (io.Writer, error, Cleanup)

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

func NewGenerator(ctx context.Context, iface *Interface, pkg string, inPackage bool, structName string) *Generator

NewGenerator builds a Generator.

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context) error

Generate builds a string that constitutes a valid go source file containing the mock of the relevant interface.

func (*Generator) GeneratePrologue

func (g *Generator) GeneratePrologue(ctx context.Context, pkg string)

GeneratePrologue generates the prologue of the mock.

func (*Generator) GeneratePrologueNote

func (g *Generator) GeneratePrologueNote(note string)

GeneratePrologueNote adds a note after the prologue to the output string.

func (*Generator) Write

func (g *Generator) Write(w io.Writer) error

type GeneratorVisitor

type GeneratorVisitor struct {
	InPackage bool
	Note      string
	Osp       OutputStreamProvider
	// The name of the output package, if InPackage is false (defaults to "mocks")
	PackageName string
	StructName  string
}

func (*GeneratorVisitor) VisitWalk

func (this *GeneratorVisitor) VisitWalk(ctx context.Context, iface *Interface) error

type Interface

type Interface struct {
	Name          string
	QualifiedName string
	FileName      string
	File          *ast.File
	Pkg           *types.Package
	Type          *types.Interface
	NamedType     *types.Named
}

type NodeVisitor

type NodeVisitor struct {
	// contains filtered or unexported fields
}

func NewNodeVisitor

func NewNodeVisitor() *NodeVisitor

func (*NodeVisitor) DeclaredInterfaces

func (n *NodeVisitor) DeclaredInterfaces() []string

func (*NodeVisitor) Visit

func (nv *NodeVisitor) Visit(node ast.Node) ast.Visitor

type OutputStreamProvider

type OutputStreamProvider interface {
	GetWriter(context.Context, *Interface) (io.Writer, error, Cleanup)
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(buildTags []string) *Parser

func (*Parser) Find

func (p *Parser) Find(name string) (*Interface, error)

func (*Parser) Interfaces

func (p *Parser) Interfaces() []*Interface

func (*Parser) Load

func (p *Parser) Load() error

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, path string) error

type StdoutStreamProvider

type StdoutStreamProvider struct {
}

func (*StdoutStreamProvider) GetWriter

func (this *StdoutStreamProvider) GetWriter(ctx context.Context, iface *Interface) (io.Writer, error, Cleanup)

type Walker

type Walker struct {
	BaseDir   string
	Recursive bool
	Filter    *regexp.Regexp
	LimitOne  bool
	BuildTags []string
}

func (*Walker) Walk

func (this *Walker) Walk(ctx context.Context, visitor WalkerVisitor) (generated bool)

type WalkerVisitor

type WalkerVisitor interface {
	VisitWalk(context.Context, *Interface) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL