inject

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package inject provides error injection for testing cloudemu services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Always

type Always struct{}

Always injects an error on every call.

func (Always) ShouldInject

func (Always) ShouldInject() bool

ShouldInject always returns true.

type Countdown

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

Countdown injects errors for the first N calls, then stops.

func NewCountdown

func NewCountdown(n int) *Countdown

NewCountdown creates a policy that injects for the first n calls.

func (*Countdown) ShouldInject

func (p *Countdown) ShouldInject() bool

ShouldInject returns true while the countdown is positive.

type Injector

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

Injector manages error injection per service/operation.

func NewInjector

func NewInjector() *Injector

NewInjector creates a new Injector.

func (*Injector) Check

func (inj *Injector) Check(service, operation string) error

Check checks if an error should be injected. Returns nil if no injection.

func (*Injector) Remove

func (inj *Injector) Remove(service, operation string)

Remove removes an error injection rule.

func (*Injector) Reset

func (inj *Injector) Reset()

Reset removes all rules.

func (*Injector) Set

func (inj *Injector) Set(service, operation string, err error, policy Policy)

Set registers an error injection rule.

type NthCall

type NthCall struct {
	N int
	// contains filtered or unexported fields
}

NthCall injects an error on every Nth call.

func NewNthCall

func NewNthCall(n int) *NthCall

NewNthCall creates a policy that injects on every Nth call.

func (*NthCall) ShouldInject

func (p *NthCall) ShouldInject() bool

ShouldInject returns true on every Nth call.

type Policy

type Policy interface {
	ShouldInject() bool
}

Policy determines when to inject an error.

type Probabilistic

type Probabilistic struct {
	Probability float64
}

Probabilistic injects errors with a given probability.

func NewProbabilistic

func NewProbabilistic(p float64) *Probabilistic

NewProbabilistic creates a policy with the given probability (0.0-1.0).

func (*Probabilistic) ShouldInject

func (p *Probabilistic) ShouldInject() bool

ShouldInject returns true with the configured probability.

type Rule

type Rule struct {
	Error  error
	Policy Policy
}

Rule is an error injection rule.

Jump to

Keyboard shortcuts

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