injection

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package injection provides error injection capabilities for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorInjection

type ErrorInjection struct {
	// PathPattern is a regex pattern to match request paths.
	PathPattern string
	// MethodPattern is a regex pattern to match HTTP methods (empty matches all).
	MethodPattern string
	// ErrorType is the type of error to inject.
	ErrorType ErrorType
	// TriggerMode defines when to trigger the error.
	TriggerMode TriggerMode
	// Probability is the probability of triggering (0-100) for TriggerModeProbability.
	Probability int
	// CountLimit is the number of times to trigger for TriggerModeCount.
	CountLimit int
	// contains filtered or unexported fields
}

ErrorInjection defines an error injection rule.

type ErrorInjector

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

ErrorInjector manages error injection rules.

func NewErrorInjector

func NewErrorInjector() *ErrorInjector

NewErrorInjector creates a new error injector.

func (*ErrorInjector) Add

func (e *ErrorInjector) Add(injection ErrorInjection) error

Add adds a new error injection rule.

func (*ErrorInjector) AddSimple

func (e *ErrorInjector) AddSimple(pathPattern string, errorType ErrorType) error

AddSimple is a convenience method to add a simple error injection.

func (*ErrorInjector) AddWithCount

func (e *ErrorInjector) AddWithCount(pathPattern string, errorType ErrorType, count int) error

AddWithCount adds an error injection that triggers for a specific count.

func (*ErrorInjector) AddWithProbability

func (e *ErrorInjector) AddWithProbability(pathPattern string, errorType ErrorType, probability int) error

AddWithProbability adds an error injection with a probability.

func (*ErrorInjector) Check

func (e *ErrorInjector) Check(path, method string) *InjectedError

Check checks if an error should be injected for the given path and method.

func (*ErrorInjector) Clear

func (e *ErrorInjector) Clear()

Clear removes all error injections.

func (*ErrorInjector) Count

func (e *ErrorInjector) Count() int

Count returns the number of active injections.

func (*ErrorInjector) Remove

func (e *ErrorInjector) Remove(pathPattern string)

Remove removes error injections matching the given path pattern.

func (*ErrorInjector) ResetCounts

func (e *ErrorInjector) ResetCounts()

ResetCounts resets all trigger counts.

type ErrorType

type ErrorType string

ErrorType defines the type of error to inject.

const (
	// ErrorTypeRateLimit simulates a 429 rate limit error.
	ErrorTypeRateLimit ErrorType = "rate_limit"
	// ErrorTypeServerError simulates a 500 server error.
	ErrorTypeServerError ErrorType = "server_error"
	// ErrorTypeTimeout simulates a request timeout.
	ErrorTypeTimeout ErrorType = "timeout"
	// ErrorTypeConflict simulates a 409 conflict error.
	ErrorTypeConflict ErrorType = "conflict"
	// ErrorTypeNotFound simulates a 404 not found error.
	ErrorTypeNotFound ErrorType = "not_found"
)

type InjectedError

type InjectedError struct {
	Type    ErrorType
	Message string
}

InjectedError represents an injected error.

type TriggerMode

type TriggerMode string

TriggerMode defines when to trigger the error.

const (
	// TriggerModeAlways always triggers the error.
	TriggerModeAlways TriggerMode = "always"
	// TriggerModeProbability triggers based on probability.
	TriggerModeProbability TriggerMode = "probability"
	// TriggerModeCount triggers for a specific number of requests.
	TriggerModeCount TriggerMode = "count"
)

Jump to

Keyboard shortcuts

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