checktest

package
v2.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package checktest holds the helpers shared by tests that compare two renderings of a /health or /ready document.

It is a package rather than a helper per test package because the callers -- kit/check, http, and cmd/influxd/launcher -- each need the same thing and cannot share a _test.go file across package boundaries. The thing they need is not incidental: two renderings of the same frozen report are equal only once the values that move on their own have been masked, and a caller that gets that set wrong writes an equality assertion that is flaky rather than one that fails.

Index

Constants

View Source
const (
	// FieldStarted and FieldUp belong to /ready alone (the http package's
	// readyBody). started is fixed at handler construction; up is the elapsed
	// time since, recomputed per request, so it advances even across a frozen
	// check set. /health carries neither.
	FieldStarted = "started"
	FieldUp      = "up"
	// FieldUptime is up again as a {"value","unit"} measure, and moves with
	// it. Only its value is masked; the unit is pinned.
	FieldUptime = "uptime"

	// FieldMessage is common to both, and moves only while it carries a
	// staleness message; see StaleMessagePattern.
	FieldMessage = "message"
	// FieldProbe is the measure group a stale check.FreshnessResponse
	// carries beside that message. Its age moves with the message; its
	// threshold does not and stays pinned.
	FieldProbe = "probe"

	SentinelStarted = "<started>"
	SentinelUp      = "<up>"
	SentinelStale   = "<stale>"
)

The fields of a rendered check document whose values move on their own, and the sentinels Normalize puts in their place.

Variables

View Source
var StaleMessagePattern = regexp.MustCompile(`^stale: last probe .* ago \(threshold .*\)$`)

StaleMessagePattern matches the message a check.FreshnessResponse renders once its snapshot has aged out. The age in it advances between two renders of the same response, so a test comparing two renders must mask it. Tracks check.staleMessage; a change to that format belongs here too.

Functions

func Normalize

func Normalize(t testing.TB, doc map[string]any) map[string]any

Normalize replaces every value in a decoded check document that moves on its own with a fixed sentinel, and returns doc, so two captures taken a moment apart compare equal on everything they actually pin.

Each field is checked for shape before it is masked, so a normalized document still fails a comparison if one of them changes type -- masking must not become a way to stop noticing. Masking is conditional on presence, because /health carries neither started nor up, and a message is masked only while it matches StaleMessagePattern: every other message is content a caller is probably asserting on, and blanking it would quietly gut the assertion.

func NormalizeJSON

func NormalizeJSON(t testing.TB, b []byte) map[string]any

NormalizeJSON decodes a rendered check document and normalizes it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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