Documentation
¶
Index ¶
- Constants
- func Err(value interface{}) *errors.Error
- func IsExternalDependency(project *Project, packagePath string) bool
- func Unpanic() func()
- type Bufferw
- type Config
- type Formatter
- type Interface
- type Package
- type PackageMapper
- func (r *PackageMapper) IndexFunc(tFunc *types.Func)
- func (r *PackageMapper) IndexImports(tPkg *types.Package)
- func (r *PackageMapper) IndexInterface(tInterface *types.Interface)
- func (r *PackageMapper) IndexSignature(tSignature *types.Signature)
- func (r *PackageMapper) IndexTuple(tTuple *types.Tuple)
- func (r *PackageMapper) ObjectTypeString(tObject types.Object) string
- func (r *PackageMapper) RecordDependency(tPkg *types.Package) string
- func (r *PackageMapper) TypeString(tType types.Type) string
- type Project
- type Signature
Constants ¶
const ( // Magic is the string used to identify files generated by Mockhiato. Magic = "// Code generated by Mockhiato. DO NOT EDIT." // InterfaceNameToken is a placeholder used in configs. InterfaceNameToken = "{interface}" // PackageNameToken is a placeholder used in configs. PackageNameToken = "{package}" // FuncNameToken is a placeholder used in configs. FuncNameToken = "{func}" )
Variables ¶
This section is empty.
Functions ¶
func IsExternalDependency ¶
IsExternalDependency returns true when `packagePath` is not a project package.
Types ¶
type Bufferw ¶
type Bufferw struct {
// contains filtered or unexported fields
}
Bufferw is a wrapper around bytes.Buffer.
func (*Bufferw) WriteString ¶
WriteString wraps bytes.Buffer.WriteString()
type Config ¶
type Config struct { Verbose bool ProjectPath string MockFileName string DependentMocksPath string StructNameFormat string DependentPackageNameFormat string MockFunctionMethodNameFormat string }
Config configures Mockhiato behavior. See mockhiato/cmd for documentation.
type Interface ¶
Interface contains metadata for an interface definition. Formatters rely on this to generate mocks.
type Package ¶
type Package struct { // Package is the package that contains interfaces. TPackage *types.Package // Interfaces contains interface definitions found in the package. Interfaces []*Interface // Signatures contains signature definitions found in the package. Signatures []*Signature }
Package contains metadata for a package discovered in the project tree. Formatters rely on this to generate mocks.
type PackageMapper ¶
type PackageMapper struct { PkgPath string PathToAlias map[string]string // contains filtered or unexported fields }
PackageMapper indexes packages and generates package aliases if required.
func NewPackageMapper ¶
func NewPackageMapper(PkgPath string) *PackageMapper
NewPackageMapper creates a new PackageMapper.
func (*PackageMapper) IndexFunc ¶
func (r *PackageMapper) IndexFunc(tFunc *types.Func)
IndexFunc indexes tFunc's dependencies.
func (*PackageMapper) IndexImports ¶
func (r *PackageMapper) IndexImports(tPkg *types.Package)
IndexImports indexes tPkg's dependencies.
func (*PackageMapper) IndexInterface ¶
func (r *PackageMapper) IndexInterface(tInterface *types.Interface)
IndexInterface indexes tInterface's dependencies.
func (*PackageMapper) IndexSignature ¶
func (r *PackageMapper) IndexSignature(tSignature *types.Signature)
IndexSignature indexes tSignature's dependencies.
func (*PackageMapper) IndexTuple ¶
func (r *PackageMapper) IndexTuple(tTuple *types.Tuple)
IndexTuple indexes tTuple's dependencies
func (*PackageMapper) ObjectTypeString ¶
func (r *PackageMapper) ObjectTypeString(tObject types.Object) string
ObjectTypeString returns the string representation of tObject's type.
func (*PackageMapper) RecordDependency ¶
func (r *PackageMapper) RecordDependency(tPkg *types.Package) string
RecordDependency indexes tPkg as a dependency and returns its name.
func (*PackageMapper) TypeString ¶
func (r *PackageMapper) TypeString(tType types.Type) string
TypeString returns the string representation of tType.
type Project ¶
type Project struct { // ProjectAbsPath is the project's absolute path. ProjectAbsPath string // GoAbsPath is $GOPATH. GoAbsPath string // GoSrcAbsPath is $GOPATH/src. GoSrcAbsPath string // PackagePath is the project's package path, which should be the relative path to $GOPATH/src. PackagePath string // VendorPath is the project's vedor path, which should be PackagePath/vendor VendorPath string // DependentMocksPath is where mocks for dependent interfaces (referenced but not defined by the project) will be created. DependentMocksPath string // Program is the loaded project Program *loader.Program // Packages is a map of packages with interfaces that needs to be mocked. Packages map[*types.Package]*Package // GenAbsPaths contains a list of generated file paths GenAbsPaths []string }
Project represents the project Mockhiato is operating on.
type Signature ¶
Signature contains metadata for a typed function. Formatters rely on this to generate mocks. Given a typed function,
type Example func(int) error
Formatters should generate a struct that implements the function's signature.
type ExampleMock struct { mock.Mock } func (r *ExampleMock) Run(int) error { ... }
Users can then use the generated struct to set up expectations and verify behavior of function parameters.
func Test(t *testing.T) { mock := &ExampleMock{} mock.On("Run", 123).Return(io.EOF) app.Execute(mock.Run) }