flowtest

package module
v0.0.0-...-19748de Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 15 Imported by: 2

README

Flow Test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asserter

type Asserter interface {
	TB
	Assertion
}

type Assertion

type Assertion interface {
	// Sub creates a named sub-assertion
	Sub(name string, args ...interface{}) Assertion

	// T accepts the assertion types like Equal which use generics and therefore
	// can't be a method of Assertion directly.
	T(failure *Failure)

	// NoError asserts that the error is nil, and fails the test if not
	NoError(err error)

	// Equal asserts that want == got. If extraLog is set, and the first
	// argument is a string it is used as a format string for the rest of the
	// arguments. If the first argument is not a string, everything is just
	// logged
	Equal(want, got interface{})

	// CodeError asserts that the error returned was non-nil and a Status error
	// with the given code
	CodeError(err error, code codes.Code)

	// NotEmpty asserts that the given values are not nil or zero values (zero
	// as in reflect.Value.IsZero)
	NotEmpty(got ...interface{})

	// NotNil asserts that the given values are not nil, assessing in order and
	// stopping at the first nil value (i.e. you can pass thing, thing.field,
	// thing.field.subfield)
	NotNil(gots ...interface{})
}

type Failure

type Failure string

func Equal

func Equal[T comparable](want, got T) *Failure

func GreaterThan

func GreaterThan[T constraints.Ordered](a, b T) *Failure

func GreaterThanOrEqual

func GreaterThanOrEqual[T constraints.Ordered](a, b T) *Failure

func LessThan

func LessThan[T constraints.Ordered](a, b T) *Failure

func LessThanOrEqual

func LessThanOrEqual[T constraints.Ordered](a, b T) *Failure

type GRPCPair

type GRPCPair struct {
	Server *grpc.Server
	Client *grpc.ClientConn
	// contains filtered or unexported fields
}

func NewGRPCPair

func NewGRPCPair(t TB, middleware ...grpc.UnaryServerInterceptor) *GRPCPair

func (*GRPCPair) ServeUntilDone

func (gg *GRPCPair) ServeUntilDone(t TB, ctx context.Context)

type LogLevel

type LogLevel string
const (
	LogLevelFatal   LogLevel = "FATAL"
	LogLevelError   LogLevel = "ERROR"
	LogLevelDefault LogLevel = ""
)

type RequiresTB

type RequiresTB interface {
	Helper()
	Log(args ...interface{})
	FailNow()
	Fail()
}

type RunnableTB

type RunnableTB[T RequiresTB] interface {
	RequiresTB
	Run(name string, f func(T)) bool
}

RunnableTB is the subset of the testing.TB interface which this library requires. Keeping it to a minimum to allow alternate implementations

type StepSetter

type StepSetter interface {
	// Setup steps run at the start of each RunSteps call, or the start of each
	// Variation. The context passed to the setup will be canceled after all steps
	// are completed, or after any fatal error.
	Setup(fn callbackErr)

	// PreStepHook runs before every step, after any variations.
	PreStepHook(fn func(context.Context, Asserter) error)

	// PreVariationHook runs before every Variation, before any steps.
	PreVariationHook(fn func(context.Context, Asserter) error)

	// PostStepHook runs after every step.
	PostStepHook(fn func(context.Context, Asserter) error)

	// Step registers a function to make assertions on the running code, this is the
	// main assertion set.
	Step(desc string, fn func(context.Context, Asserter))

	// Adds a variation to the stepper. Each Variation causes the Setup hooks,
	// followed by the Variation, then every registered Step (and hooks), allowing
	// one call to RunSteps to run multiple variations of the same test.
	Variation(desc string, fn func(context.Context, Asserter))

	// LevelLog implements a global logger compatible with pentops/log.go/log.
	// Log lines will be captured into the currently running test step.
	LevelLog(level, message string, fields map[string]interface{})

	// Log logs any object, it can be used within test callbacks.
	// Log lines will be captured into the currently running test step.
	Log(...interface{})
}

StepSetter is a minimal interface to configure the steps and hooks for a test.

type Stepper

type Stepper[T RequiresTB] struct {
	// contains filtered or unexported fields
}

func NewStepper

func NewStepper[T RequiresTB](name string) *Stepper[T]

func (*Stepper[T]) LevelLog

func (ss *Stepper[T]) LevelLog(level, message string, fields map[string]interface{})

LevelLog implements a global logger compatible with pentops/log.go/log DefaultLogger, and others, to capture log lines from within the handlers into the test output

func (*Stepper[T]) Log

func (ss *Stepper[T]) Log(args ...interface{})

func (*Stepper[T]) PostStepHook

func (ss *Stepper[T]) PostStepHook(fn func(context.Context, Asserter) error)

PostStepHook runs after every step.

func (*Stepper[T]) PreStepHook

func (ss *Stepper[T]) PreStepHook(fn func(context.Context, Asserter) error)

PreStepHook runs before every step, after any variations.

func (*Stepper[T]) PreVariationHook

func (ss *Stepper[T]) PreVariationHook(fn func(context.Context, Asserter) error)

PreVariationHook runs before every Variation, before any steps.

func (*Stepper[T]) RunSteps

func (ss *Stepper[T]) RunSteps(t RunnableTB[T])

RunSteps is the main entry point of the stepper. For each Variation, or just once if no variation is registered, the Setup hooks are run, followed by the Variation, then every registered Step with pre and post hoooks.

func (*Stepper[T]) RunStepsWithContext

func (ss *Stepper[T]) RunStepsWithContext(ctx context.Context, t RunnableTB[T])

RunStepsWithContext allows the caller to provide a context to the stepper.

func (*Stepper[T]) Setup

func (ss *Stepper[T]) Setup(fn callbackErr)

Setup steps run at the start of each RunSteps call, or the start of each Variation. The context passed to the setup will be canceled after all steps are completed, or after any fatal error.

func (*Stepper[_]) Step

func (ss *Stepper[_]) Step(desc string, fn func(context.Context, Asserter))

Step registers a function to make assertions on the running code, this is the main assertion set.

func (*Stepper[_]) Variation

func (ss *Stepper[_]) Variation(desc string, fn func(context.Context, Asserter))

Adds a variation to the stepper. Each Variation causes the Setup hooks, followed by the Variation, then every registered Step (and hooks), allowing one call to RunSteps to run multiple variations of the same test.

type TB

type TB interface {
	//Cleanup(func())
	Error(args ...any)
	Errorf(format string, args ...any)
	//Fail()
	FailNow()
	Failed() bool
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
}

TB is the subset of the testing.TB interface which the stepper's asserter implements.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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