mock

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Method

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

Method represents a method that is being mocked.

func MethodFor

func MethodFor(receiver Mock, name string, typ *ast.FuncType) Method

MethodFor returns a Method representing typ, using receiver as the Method's receiver type and name as the method name.

func (Method) Ast

func (m Method) Ast() *ast.FuncDecl

Ast returns the ast representation of m.

func (Method) Fields

func (m Method) Fields() []*ast.Field

Fields returns the fields that need to be a part of the receiver struct for this method.

func (Method) PrependLocalPackage

func (m Method) PrependLocalPackage(name string)

PrependLocalPackage prepends name as the package name for local types in m's signature. This is most often used when mocking types that are imported by the local package.

type Mock

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

Mock is a mock of an interface type.

func For

func For(typ *ast.TypeSpec) (Mock, error)

For returns a Mock representing typ. An error will be returned if a mock cannot be created from typ.

func (Mock) Ast

func (m Mock) Ast(chanSize int) []ast.Decl

Ast returns all declaration AST for m.

func (Mock) Constructor

func (m Mock) Constructor(chanSize int) *ast.FuncDecl

Constructor returns a function AST to construct m. chanSize will be the buffer size for all channels initialized in the constructor.

func (Mock) Decl

func (m Mock) Decl() *ast.GenDecl

Decl returns the declaration AST for m.

func (Mock) Methods

func (m Mock) Methods() (methods []Method)

Methods returns the methods that need to be created with m as a receiver.

func (Mock) Name

func (m Mock) Name() string

Name returns the type name for m.

func (Mock) PrependLocalPackage

func (m Mock) PrependLocalPackage(name string)

PrependLocalPackage prepends name as the package name for local types in m's signature. This is most often used when mocking types that are imported by the local package.

func (Mock) SetBlockingReturn

func (m Mock) SetBlockingReturn(blockingReturn bool)

SetBlockingReturn sets whether or not methods will include a blocking return channel, most often used for testing data races.

type Mocks

type Mocks []Mock

Mocks is a slice of Mock values.

func Generate

func Generate(finder TypeFinder) (Mocks, error)

Generate generates a Mocks value for all exported interface types returned by finder.

func (Mocks) Output

func (m Mocks) Output(pkg, dir string, chanSize int, dest io.Writer) error

Output writes the go code representing m to dest. pkg will be the package name; dir is the destination directory (needed for formatting the file); chanSize is the buffer size of any channels created in constructors.

func (Mocks) PrependLocalPackage

func (m Mocks) PrependLocalPackage(name string)

PrependLocalPackage prepends name as the package name for local types in m's signature. This is most often used when mocking types that are imported by the local package.

func (Mocks) SetBlockingReturn

func (m Mocks) SetBlockingReturn(blockingReturn bool)

SetBlockingReturn sets whether or not methods will include a blocking return channel, most often used for testing data races.

type TypeFinder

type TypeFinder interface {
	ExportedTypes() (types []*ast.TypeSpec)
	Dependencies(name string) (dependencies []typ.Dependency)
}

TypeFinder represents a type which knows about types and dependencies.

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL