clock

package
v0.27.0-rc.17 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 1 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Freeze

func Freeze(t interface{ Cleanup(func()) }, ts time.Time)

Freeze makes Now return ts until t and its subtests finish, then puts back the backend it replaced. Calls nest: an inner Freeze gives back the outer one when its test ends. The backend is process-global, so a test that calls Freeze must not run in parallel with one that reads the clock.

func Now

func Now() time.Time

Now returns the current time from the package's backend. Use it rather than time.Now everywhere but a deadline or an elapsed-time measurement, so a test can control what "now" means.

func Set

func Set(t interface{ Cleanup(func()) }, c Clock)

Set serves Now from c until t and its subtests finish, then puts back the backend it replaced. Use it when a test needs Now to change; Freeze covers a single instant. Like Freeze, it swaps a process-global backend and is not safe under t.Parallel.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock is an interface that can provide time related functionality which allows us to test time dependent code.

var DefaultBackend Clock

DefaultBackend is used to configure the defaultBackend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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