delta

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package delta handles run-over-run comparison for test results and coverage. A Snapshot captures the key metrics from one run; two snapshots produce a Delta which the HTML renderers use to display change badges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatIntDelta

func FormatIntDelta(d int) string

FormatIntDelta returns "+N" or "-N" or "0".

func FormatPctDelta

func FormatPctDelta(d float64) string

FormatPctDelta returns a human-readable signed string like "+2.3%" or "-1.1%".

func Save

func Save(path string, snap *Snapshot) error

Save writes snap to path as JSON.

Types

type CoverageSnap

type CoverageSnap struct {
	LinesPct    float64 `json:"lines_pct"`
	LinesCov    int     `json:"lines_covered"`
	LinesTotal  int     `json:"lines_total"`
	BranchPct   float64 `json:"branch_pct"`
	BranchCov   int     `json:"branch_covered"`
	BranchTotal int     `json:"branch_total"`
	FuncPct     float64 `json:"func_pct"`
	FuncCov     int     `json:"func_covered"`
	FuncTotal   int     `json:"func_total"`
	// Files maps each file path to its line coverage percentage.
	// Used to produce per-file deltas when comparing two snapshots.
	Files map[string]float64 `json:"files,omitempty"`
}

CoverageSnap holds coverage metrics.

func FromCovReport

func FromCovReport(rep *covmodel.CovReport) *CoverageSnap

FromCovReport builds a CoverageSnap from a parsed coverage report.

type Delta

type Delta struct {
	// Tests
	TotalDelta   int
	PassedDelta  int
	FailedDelta  int
	SkippedDelta int
	HasTests     bool

	// Coverage — overall
	LinesPctDelta  float64
	BranchPctDelta float64
	FuncPctDelta   float64
	HasCoverage    bool

	// Coverage — per-file line coverage deltas (path → Δ%).
	// Only populated for files present in both baseline and current.
	FileDeltas map[string]float64
}

Delta is the computed difference between a baseline and current snapshot.

func Compute

func Compute(baseline, current *Snapshot) *Delta

Compute calculates the delta between baseline and current. Either field of current/baseline may be nil (treated as "not available").

type Snapshot

type Snapshot struct {
	Version   int    `json:"version"`
	Timestamp string `json:"timestamp"`
	Label     string `json:"label,omitempty"`

	Tests    *TestSnap     `json:"tests,omitempty"`
	Coverage *CoverageSnap `json:"coverage,omitempty"`
}

Snapshot is the machine-readable summary of one run, saved to JSON. It can represent tests-only, coverage-only, or a combined run.

func Load

func Load(path string) (*Snapshot, error)

Load reads a snapshot from path. It returns an error if the file cannot be read, the JSON is malformed, or the snapshot version is newer than what this build supports.

type TestSnap

type TestSnap struct {
	Total   int `json:"total"`
	Passed  int `json:"passed"`
	Failed  int `json:"failed"`
	Skipped int `json:"skipped"`
}

TestSnap holds test result metrics.

func FromTestReport

func FromTestReport(rep *testmodel.Report) *TestSnap

FromTestReport builds a TestSnap from a parsed test report.

Jump to

Keyboard shortcuts

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