test

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// InternalOptions is internal variable, exported for cross-package access
	// InternalOptions holds common setup/teardown hooks of all tests in same package.
	// testsuite package has options to set this list
	// Note, when executing all tests, golang run tests on per-package basis
	InternalOptions = make([]Options, 0)
)

Functions

func FuncName

func FuncName(fn interface{}, suffixed bool) string

FuncName returns a name that could potentially used as sub test name function panic if given fn is not func

func InternalRunSubTests

func InternalRunSubTests(ctx context.Context, t *T)

InternalRunSubTests is an internal function. exported for cross-package reference

func NewHook

func NewHook(order int, setupFunc SetupFunc, teardownFunc TeardownFunc) *orderedHook

func NewSetupHook

func NewSetupHook(order int, setupFunc SetupFunc) *orderedHook

func NewTeardownHook

func NewTeardownHook(order int, teardownFunc TeardownFunc) *orderedHook

func RunTest

func RunTest(ctx context.Context, t *testing.T, opts ...Options)

RunTest is the entry point of any Test...(). It takes any context, and run sub tests according to provided Options

Types

type GomegaSubTestFunc

type GomegaSubTestFunc func(ctx context.Context, t *testing.T, g *gomega.WithT)

GomegaSubTestFunc is the function signature for sub-test that taking a context and gomega.WithT, and can be registered as SubTest Options

type Hook

type Hook interface {
	Setup(ctx context.Context, t *testing.T) (context.Context, error)
	Teardown(ctx context.Context, t *testing.T) error
}

Hook is registered for tests and sub tests, should provide SetupFunc or TeardownFunc (or both) This interface is mostly internal usage. Test implementers typically use Options to create instance of this interface

type InternalRunner

type InternalRunner func(context.Context, *T)

InternalRunner is an internal type, exported for cross-package reference

type Options

type Options func(opt *T)

Options are test config functions to pass into RunTest

func AnonymousSubTest

func AnonymousSubTest(st SubTestFunc) Options

AnonymousSubTest is an Options that run a SubTestFunc as generated name

func GomegaSubTest

func GomegaSubTest(st GomegaSubTestFunc, name ...string) Options

GomegaSubTest is an Options that run a GomegaSubTestFunc as given name. If name is not given, a generated name is used Note: when name is given as multiple arguments, the first element is used as format and the rest is used as args:

fmt.Sprintf(name[0], name[1:])

func Hooks

func Hooks(hooks ...Hook) Options

Hooks is an Options that register multiple Hook. Test implementers are recommended to use Setup or Teardown instead

func Setup

func Setup(fn SetupFunc) Options

Setup is an Options that register the SetupFunc to run before ANY sub tests starts

func SubTest

func SubTest(subtest SubTestFunc, name string) Options

SubTest is an Options that run a SubTestFunc as given name

func SubTestSetup

func SubTestSetup(fn SetupFunc) Options

SubTestSetup is an Options that register a SetupFunc to run before each sub test

func SubTestTeardown

func SubTestTeardown(fn TeardownFunc) Options

SubTestTeardown is an Options that register a TeardownFunc to run after each sub test

func Teardown

func Teardown(fn TeardownFunc) Options

Teardown is an Options that register the TeardownFunc to run after ALL sub tests finishs

func WithInternalRunner

func WithInternalRunner(runner InternalRunner) Options

WithInternalRunner is internal option, exported for cross-platform access

func WithOptions

func WithOptions(opts ...Options) Options

WithOptions group multiple options into one. This is mostly used by other testing utilities to provide grouped test configs

type SetupFunc

type SetupFunc func(ctx context.Context, t *testing.T) (context.Context, error)

type SubTestFunc

type SubTestFunc func(ctx context.Context, t *testing.T)

SubTestFunc is the function signature for sub-test that taking a context and can be registered as SubTest Options

func SubTestFuncWithGomega

func SubTestFuncWithGomega(st GomegaSubTestFunc) SubTestFunc

SubTestFuncWithGomega convert a GomegaSubTestFunc to SubTestFunc

type SubTestOrderedMap

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

SubTestOrderedMap adopted from https://github.com/elliotchance/orderedmap/blob/master/orderedmap.go with reduced functionality

func NewSubTestOrderedMap

func NewSubTestOrderedMap() *SubTestOrderedMap

func (*SubTestOrderedMap) Delete

func (m *SubTestOrderedMap) Delete(key string) (didDelete bool)

Delete will remove a name from the map. It will return true if the name was removed (the name did exist).

func (*SubTestOrderedMap) Get

func (m *SubTestOrderedMap) Get(key string) (SubTestFunc, bool)

func (*SubTestOrderedMap) Keys

func (m *SubTestOrderedMap) Keys() (keys []string)

func (*SubTestOrderedMap) Len

func (m *SubTestOrderedMap) Len() int

func (*SubTestOrderedMap) Set

func (m *SubTestOrderedMap) Set(name string, fn SubTestFunc) bool

type T

type T struct {
	*testing.T

	TestHooks    []Hook
	SubTestHooks []Hook
	SubTests     *SubTestOrderedMap
	// contains filtered or unexported fields
}

T embed *testing.T and holds additional information of test config

type TeardownFunc

type TeardownFunc func(ctx context.Context, t *testing.T) error

Directories

Path Synopsis
Package consultest Leveraging ittest package and HTTP VCR to record and replay consul operations
Package consultest Leveraging ittest package and HTTP VCR to record and replay consul operations
authmock
Package mock_security is a generated GoMock package.
Package mock_security is a generated GoMock package.
internal
Package internal is an internal package that help to test generated mocks
Package internal is an internal package that help to test generated mocks
redismock
Package redismock is a generated GoMock package.
Package redismock is a generated GoMock package.
sessionmock
Package mock_session is a generated GoMock package.
Package mock_session is a generated GoMock package.
Package sdtest test utilities to mock service discovery client
Package sdtest test utilities to mock service discovery client
golden
Package golden will contain some utility functions for golden file testing
Package golden will contain some utility functions for golden file testing

Jump to

Keyboard shortcuts

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