clocktest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clocktest pins clock.Now for the tests of a package.

A test package whose code under test reads the clock calls Freeze once, from its TestMain, before m.Run, and builds its fixtures relative to Instant. Tests never reassign clock.Now and never restore it: a test that needs another instant passes it explicitly (evaluation date, currentDateTime, ...).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Freeze

func Freeze()

Freeze pins clock.Now to Instant. Call it from TestMain only, before m.Run.

func FreezeStepping

func FreezeStepping(step time.Duration)

FreezeStepping pins clock.Now to a deterministic stepping clock: the first call returns Instant, and every following call returns a time that is step later than the previous one (strictly increasing and safe for concurrent use, with no relation to the real time). It is for the packages whose tests assert that a date advances (a cache refresh after a poll or a forced refresh). Call it from TestMain only, before m.Run, and never reassign the clock afterwards.

func Instant

func Instant() time.Time

Instant is the fixed instant that Freeze pins the clock to.

Types

This section is empty.

Jump to

Keyboard shortcuts

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