makegomock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(w io.Writer, typ *types.Named, pkgName, importPath, rename string, bare bool) error

Generate generates mock code into w that mocks the specified type in a Go source file at the given package name and import path.

If rename is empty, the generated type name will be based on typ.

func GenerateToFileFromFile

func GenerateToFileFromFile(
	dstFileOrDirPath,
	dstPkgName,
	dstTypeName,
	srcPath,
	srcPkgName,
	srcTypeName string,
	bare bool,
) (dstFilePath string, err error)

GenerateToFileFromFile is a convenience function that combines Resolve, Generate and operations on the file system to write the generated mock code to a file.

func Resolve

func Resolve(
	dstFileOrDirPath,
	dstPkgName,
	dstTypeName,
	srcPkgName,
	srcImportPath,
	srcTypeName string,
) (filePath, pkgName, importPath, typeName string, err error)

Resolve resolves the destination file path, package name and import path.

If dstPkgName is empty, pkgName will be the name of the destination directory, or srcPkgName if the destination directory is the current directory.

The destination directory is resolved from dstFileOrDirPath. If empty, the current directory is used. If a path to what looks like a Go source file, its base directory is used. Otherwise, it is taken to be the explicit path to the destination directory.

If dstFileOrDirPath didn't specify a destination Go source file, filePath is resolved from typeName by prefixing with 'mock_' and suffixing with '_test.go'.

If dstTypeName is left empty, srcTypeName is used.

The import path is resolved from the destination directory and srcImportPath. The destination directory must be resolved to a path that is under srcImportPath.

Types

type Errors

type Errors struct {
	Err  error
	Errs []error
}

Errors is an error caused by multiple errors.

func (Errors) Error

func (errs Errors) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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