fault

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fault defines fault behaviors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fault

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

Fault describes the behavior of a single fault.

func New

func New() *Fault

New creates a new fault.

func (*Fault) Before

func (f *Fault) Before(cb func()) *Fault

Before invokes the provided function but does not return an error.

func (*Fault) ErrorCallbackInstead

func (f *Fault) ErrorCallbackInstead(cb func() error) *Fault

ErrorCallbackInstead invokes the provided function to return the error instead of calling the method.

func (*Fault) ErrorInstead

func (f *Fault) ErrorInstead(err error) *Fault

ErrorInstead causes the fault to return the provided error instead of calling the method.

func (*Fault) Repeat

func (f *Fault) Repeat(n int) *Fault

Repeat causes the fault to repeat N times.

func (*Fault) SleepFor

func (f *Fault) SleepFor(d time.Duration) *Fault

SleepFor sleeps for the specified amount of time.

type Method

type Method int

Method indicates a method with fault injection.

type Set

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

Set encapsulates a set of faults.

func NewSet added in v0.13.0

func NewSet() *Set

func (*Set) AddFault

func (s *Set) AddFault(method Method) *Fault

AddFault adds a new fault for a given method.

func (*Set) AddFaults

func (s *Set) AddFaults(method Method, faults ...*Fault)

AddFaults adds a new fault for a given method.

func (*Set) GetNextFault

func (s *Set) GetNextFault(ctx context.Context, method Method, args ...interface{}) (bool, error)

GetNextFault returns the error message to return on next fault.

func (*Set) NumCalls

func (s *Set) NumCalls(method Method) int

NumCalls returns the number of calls for a particular method.

func (*Set) VerifyAllFaultsExercised

func (s *Set) VerifyAllFaultsExercised(t *testing.T)

VerifyAllFaultsExercised fails the test if some faults have not been exercised.

Jump to

Keyboard shortcuts

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