ttgenlib

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 13 Imported by: 0

README

ttgenlib

A framework to simplify building table test generators for functions and methods, with:

  • Customizable context.Context treatment.
  • Fields and function/method parameters are getting nice helpers to use mock objects for them.

You only need to define your messages renderer (result err processing) and provide mock lookup. The standard lookup function will probably be sufficient for your needs at that.

See example for implementation details.

Documentation

Overview

Package ttgenlib is a framework to create table tests generators with ease.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(
	appName string,
	mockLookup MockLookup,
	logging GenLoggingRenderer,
	genOpts ...GenOption,
) error

Run table tests generation with a given names and handlers.

Types

type GenLoggingRenderer added in v0.0.2

type GenLoggingRenderer = generator.LoggingRenderer

GenLoggingRenderer renders error messages. These variables:

t *testing.T
err error

are available in the generation scope to use.

type GenOption added in v0.0.2

type GenOption = generator.Option

GenOption code generation option type.

func GenCtxInit added in v0.0.2

func GenCtxInit(ctxinit GenUserDefinedCodeRenderer) GenOption

GenCtxInit overrides default context.Context initialization code rendering.

func GenMockContext added in v0.0.2

func GenMockContext() GenOption

GenMockContext enables mocking for context.Context parameter or field.

func GenMockerNames added in v0.0.2

func GenMockerNames(
	f func(tn *types.TypeName) (filename string, typename string),
) GenOption

GenMockerNames this option is used to override default mocker file and type name generation. It is <type_name>_mocker_test.go and <typeName>Mocker by default.

func GenNoMock added in v0.0.2

func GenNoMock(pkgname, typename string) GenOption

GenNoMock adds an interface tye that does not need to be mocked. context.Context is one by default. Use GenMockContext to override this.

func GenPreTest added in v0.0.2

func GenPreTest(pretest GenUserDefinedCodeRenderer) GenOption

GenPreTest is a generator which can be used to put some additional code just after ctrl := ... part and right before everything else in the test logic.

type GenUserDefinedCodeRenderer added in v0.0.2

type GenUserDefinedCodeRenderer = func(r *gogh.GoRenderer[*gogh.Imports])

GenUserDefinedCodeRenderer just a shortcut for hard to read function type defintion.

type MockLookup added in v0.0.2

type MockLookup = generator.MockLookup

MockLookup a (functional) type to look for mocks for a given type.

func StandardMockLookup added in v0.0.2

func StandardMockLookup(altPaths []string, template string, custom map[string]string) MockLookup

StandardMockLookup this is a mock lookup function that is seemingly sufficient for Google's mockgen and pamgen mock generators.

  • altPaths is a list of package paths to look in if no mock was found in object's own package.
  • template is a template for mock type name based on the type name. Will look be "Mock${type}" for mockgen and "${type|P}Mock" for pamgen. P is the formatting option to translate original type name into the public one, `pamgen` always translates mock names into public form.
  • custom map can specify mock type names for certain types.

It looks for a mock type in the given type's package first, then move to altPaths provided if no match was found. These criteria must be satisfied:

  • The mock type name must be equal to template with type name applied to it.
  • The mock type must implement the given type (it is an interface).
  • There should be a function NewXXX(*gomock.Controller) *XXX in the package, where XXX is a mock type name.

type MockLookupResult added in v0.0.2

type MockLookupResult = generator.MockLookupResult

MockLookupResult a result to be returned when a mock for a given type was found.

Directories

Path Synopsis
internal
extmocks
Package extmocks mocks for outer interfaces are here.
Package extmocks mocks for outer interfaces are here.
generator
Package generator deals with code generation.
Package generator deals with code generation.
ordmap
Package ordmap implements ordered map.
Package ordmap implements ordered map.
predictor
Package predictor to define command line predictions.
Package predictor to define command line predictions.

Jump to

Keyboard shortcuts

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