coverage

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	LoadSpec(r io.Reader) (err error)
	ReportFailure(endpoint common.Endpoint, method common.Method, req *http.Request, err error)
	ReportUnmet(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation, err error)
	ReportMet(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation)
	ReportSkipped(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation)
	ReportTiming(endpoint common.Endpoint, method common.Method, req *http.Request, dur time.Duration, tt *TraceTiming)
	HasFailures() bool
}

Collector is the interface for collecting coverage information

func NewNullCoverage

func NewNullCoverage() Collector

type Common

type Common struct {
	Failures []Failure
	Unmet    []Unmet
	Met      []Met
	Skipped  []Skip
	Timings  Timings
}

Common provides common coverage information

type Coverage

type Coverage struct {
	Endpoints map[string]*Endpoint
	OAS       *chioas.Definition
	Common
	// contains filtered or unexported fields
}

Coverage is the default coverage information

func NewCoverage

func NewCoverage() *Coverage

func (*Coverage) HasFailures

func (c *Coverage) HasFailures() bool

func (*Coverage) LoadSpec

func (c *Coverage) LoadSpec(r io.Reader) (err error)

func (*Coverage) ReportFailure

func (c *Coverage) ReportFailure(endpoint common.Endpoint, method common.Method, req *http.Request, err error)

func (*Coverage) ReportMet

func (c *Coverage) ReportMet(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation)

func (*Coverage) ReportSkipped

func (c *Coverage) ReportSkipped(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation)

func (*Coverage) ReportTiming

func (c *Coverage) ReportTiming(endpoint common.Endpoint, method common.Method, req *http.Request, dur time.Duration, tt *TraceTiming)

func (*Coverage) ReportUnmet

func (c *Coverage) ReportUnmet(endpoint common.Endpoint, method common.Method, req *http.Request, exp common.Expectation, err error)

func (*Coverage) SpecCoverage

func (c *Coverage) SpecCoverage() (*Spec, error)

type Endpoint

type Endpoint struct {
	Endpoint common.Endpoint
	Methods  map[string]*Method
	Common
}

Endpoint provides coverage information about an endpoint

type Failure

type Failure struct {
	Endpoint common.Endpoint
	Method   common.Method
	Request  *http.Request
	Error    error
}

Failure provides coverage information about a failure

type Met

type Met struct {
	Endpoint    common.Endpoint
	Method      common.Method
	Request     *http.Request
	Expectation common.Expectation
}

Met provides coverage information about a met expectation

type Method

type Method struct {
	Method common.Method
	Common
}

Method provides coverage information about a method

type Skip

type Skip struct {
	Endpoint    common.Endpoint
	Method      common.Method
	Request     *http.Request
	Expectation common.Expectation
}

Skip provides coverage information about a skipped expectation

type Spec

type Spec struct {
	CoveredPaths    map[string]*SpecPath
	NonCoveredPaths map[string]*SpecPath
	UnknownPaths    map[string]*SpecPath
}

Spec provides coverage information against a supplied OAS

func (*Spec) MethodsCovered

func (s *Spec) MethodsCovered() (total int, covered int, perc float64)

func (*Spec) PathsCovered

func (s *Spec) PathsCovered() (total int, covered int, perc float64)

type SpecMethod

type SpecMethod struct {
	Method    string
	MethodDef *chioas.Method
	Common
}

type SpecPath

type SpecPath struct {
	Path              string
	PathDef           *chioas.Path
	CoveredMethods    map[string]*SpecMethod
	NonCoveredMethods map[string]*SpecMethod
	UnknownMethods    map[string]*SpecMethod
}

type Timing

type Timing struct {
	Endpoint common.Endpoint
	Method   common.Method
	Request  *http.Request
	Duration time.Duration
	Trace    *TraceTiming
}

Timing provides coverage information about an individual endpoint+method call

type TimingStats

type TimingStats struct {
	// Mean is the mean average response time. Gives a sense of typical latency under the current test conditions
	Mean time.Duration
	// StdDev is the standard deviation - how much individual response times deviate from the mean.
	//
	// A small StdDev means responses are consistent; a large one means erratic latency
	StdDev time.Duration // sqrt(Variance)
	// Variance is how much response times vary - in squared seconds.
	//
	// The lower the value, the better.  A high value indicates jitter and inconsistent response times
	Variance float64 // in seconds²
	// Minimum is the fastest observed response time. Indicates best-case performance
	Minimum time.Duration
	// Maximum is the slowest observed response time. Often reveals worst-case outliers (e.g., cold starts, timeouts)
	Maximum time.Duration
	// P50 is the median response time - half the runs were faster, half slower.
	//
	// Unlike Mean, it’s robust to outliers.  Indicates “Typical” latency.
	P50 time.Duration
	// P90 is the 90th percentile of response times - 9 out of 10 runs were this fast or faster.
	//
	// Useful for SLO/SLA checks.
	P90 time.Duration
	// P99 is the 99th percentile of response times - highlights rare but serious tail latencies.
	P99 time.Duration
	// Count is how many timings the stats are based on.
	//
	// Important for trustworthiness: low counts mean less reliable percentiles.
	Count int
	// Sample is whether the Variance / StdDev were computed using sample (n-1) or population (n) denominator — mostly for internal correctness.
	Sample bool
}

TimingStats is the timing statistics (as returned by Timings.Stats)

type Timings

type Timings []Timing

Timings is a slice of Timing

func (Timings) Outliers

func (ct Timings) Outliers(percentile float64) []Timing

Outliers returns the subset of timings whose Duration is at or above the given percentile threshold (upper-tail). For example, p=0.99 returns the slowest ~1% of requests. If timings is empty, returns nil. Percentile is clamped into [0,1]. p==0 returns all, p==1 returns only the max(es).

Returned timings are sorted - slowest appearing last

func (Timings) Stats

func (ct Timings) Stats(sample bool) (TimingStats, bool)

Stats creates a TimingStats from the Timings

sample arg determines whether resulting TimingStats.StdDev & TimingStats.Variance are computed using sample (n-1) or population (n)

func (Timings) StatsTTFB

func (ct Timings) StatsTTFB(sample bool) (TimingStats, bool)

StatsTTFB creates a TimingStats from the Timings TTFB (if collected)

sample arg determines whether resulting TimingStats.StdDev & TimingStats.Variance are computed using sample (n-1) or population (n)

type TraceTiming

type TraceTiming struct {
	Start               time.Time
	DNSStart, DNSDone   time.Time
	ConnStart, ConnDone time.Time
	TLSStart, TLSDone   time.Time
	WroteReq            time.Time
	FirstByte           time.Time
	ReusedConn          bool
	TTFB                time.Duration
}

TraceTiming is used for more precise timing information (use with.TraceTimings to collect this information)

type Unmet

type Unmet struct {
	Endpoint    common.Endpoint
	Method      common.Method
	Request     *http.Request
	Expectation common.Expectation
	Error       error
}

Unmet provides coverage information about an unmet expectation

Jump to

Keyboard shortcuts

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