faults

package
v0.10.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package faults provides common headers and client-side fault injection functionality.

Index

Constants

View Source
const (
	FaultServerAddressHeader   = "x-bp-fault-server-address"
	FaultServerMethodHeader    = "x-bp-fault-server-method"
	FaultDelayMsHeader         = "x-bp-fault-delay-ms"
	FaultDelayPercentageHeader = "x-bp-fault-delay-percentage"
	FaultAbortCodeHeader       = "x-bp-fault-abort-code"
	FaultAbortMessageHeader    = "x-bp-fault-abort-message"
	FaultAbortPercentageHeader = "x-bp-fault-abort-percentage"
)

Variables

This section is empty.

Functions

func WithDefaultAbort

func WithDefaultAbort[T any](fn Abort[T]) func(*Injector[T])

WithDefaultAbort is an option to set the default abort function for the Injector.

Types

type Abort

type Abort[T any] func(code int, message string) (T, error)

Abort is the function type to inject a protocol-specific fault with the given code and message.

type Headers

type Headers interface {
	// Lookup returns the value of a protocol-specific header with the
	// given key.
	Lookup(ctx context.Context, key string) (string, error)
}

Headers is an interface to be implemented by the caller to allow protocol-specific header lookup. Using an interface here rather than a function type avoids any potential closure requirements of a function.

type Injector

type Injector[T any] struct {
	// contains filtered or unexported fields
}

Injector contains the data common across all requests needed to inject faults on outgoing requests.

func NewInjector

func NewInjector[T any](clientName, callerName string, abortCodeMin, abortCodeMax int, option ...func(*Injector[T])) *Injector[T]

NewInjector creates a new Injector with the provided parameters.

func (*Injector[T]) Inject

func (i *Injector[T]) Inject(ctx context.Context, address, method string, headers Headers, resume Resume[T]) (T, error)

Inject injects a fault using the Injector default fault function on the outgoing request if it matches the header configuration.

func (*Injector[T]) InjectWithAbortOverride

func (i *Injector[T]) InjectWithAbortOverride(ctx context.Context, address, method string, headers Headers, resume Resume[T], abort Abort[T]) (T, error)

InjectWithAbortOverride injects a fault using the provided fault function on the outgoing request if it matches the header configuration.

type Resume

type Resume[T any] func() (T, error)

Resume is the function type to continue processing the protocol-specific request without injecting a fault.

Jump to

Keyboard shortcuts

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