faketime

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package faketime fakes time for tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoAdvance

func AutoAdvance(t time.Time, dt time.Duration) func() time.Time

AutoAdvance returns a time source function that returns a time equal to 't + ((n - 1) * dt)' wheren n is the number of serialized invocations of the returned function. The returned function will generate a time series of the form [t, t+dt, t+2dt, t+3dt, ...]

func Frozen

func Frozen(t time.Time) func() time.Time

Frozen returns a function that always returns t

Types

type TimeAdvance

type TimeAdvance struct {
	// contains filtered or unexported fields
}

TimeAdvance allows controlling the passage of time. Intended to be used in tests.

func NewTimeAdvance

func NewTimeAdvance(start time.Time) *TimeAdvance

NewTimeAdvance creates a TimeAdvance with the given start time

func (*TimeAdvance) Advance

func (t *TimeAdvance) Advance(dt time.Duration) time.Time

Advance advances t by dt, such that the next call to t.NowFunc()() returns current t + dt

func (*TimeAdvance) NowFunc

func (t *TimeAdvance) NowFunc() func() time.Time

NowFunc returns a time provider function for t

Jump to

Keyboard shortcuts

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