fault

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package fault provides facilities for simulated fault injection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contingency

type Contingency func(f Fault) bool

Contingency is a condition under which a fault should be injected. It is effectively a predicate; if it evaluates to true, a fault will be injected. Otherwise, if false, no fault will be returned to the application.

func After

func After(n int) Contingency

After is a contingency that occurs after the first n attempts.

func Always

func Always() Contingency

Always is a contingency that always occurs.

func First

func First(n int) Contingency

First is a contingency that occurs during the first n attempts.

func Never

func Never() Contingency

Never is a contingency that never occurs.

func Random

func Random(p float32) Contingency

Random is a contingency that occurs with a probability equal to the given p-value.

type Fault

type Fault interface {
	Try() error
	Calls() int
	Faults() int
}

Fault is an injector of simulated errors. A single fault instance should be spawned for one test.

A fault is thread-safe; it can be invoked from multiple goroutines.

type Spec

type Spec struct {
	Cnt Contingency
	Err error
}

Spec outlines the conditions for a fault, comprising a contingency, as well as an error that is reported when said contingency arises.

Specifications are completely reusable; one can create multiple Fault objects from a single Spec. Fault objects, on the other hand, should not be reused as they encompass invocation counters.

func None

func None() Spec

None is a convenience function for specifying a no-fault.

func (Spec) Build

func (s Spec) Build() Fault

Build creates a Fault instance from its Spec.

Jump to

Keyboard shortcuts

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