clock

package
v7.0.0-...-1c7ecba Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(d time.Duration) error

Add moves the mocked global clock forward the given duration. It will error if the global clock is not mocked.

func Reset

func Reset() *clockapi.Mock

Reset sets the global clock to a pure time implementation. Returns any existing Mock if set in case lingering time operations are attached to it.

func Set

func Set(t time.Time)

Set the global clock to a clockapi.Mock with the given time.Time

Types

type Clock

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

Clock is a non-package level wrapper around time that supports stubbing. It will use its localized stubs (allowing for parallelized unit tests where package level stubbing would cause issues). It falls back to any package level time stubs for non-parallel, cross-package integration testing scenarios.

If nothing is stubbed, it defaults to default time behavior in the time package.

func (*Clock) Add

func (c *Clock) Add(d time.Duration) error

Add moves clock forward time.Duration if it is mocked. It will error if the clock is not mocked.

func (*Clock) After

func (c *Clock) After(d time.Duration) <-chan time.Time

func (*Clock) AfterFunc

func (c *Clock) AfterFunc(d time.Duration, f func()) *clockapi.Timer

func (*Clock) Now

func (c *Clock) Now() time.Time

func (*Clock) Reset

func (c *Clock) Reset() *clockapi.Mock

Reset removes local clock.Mock. Returns any existing Mock if set in case lingering time operations are attached to it.

func (*Clock) Set

func (c *Clock) Set(t time.Time)

Set sets the Clock to a clock.Mock at the given time.Time

func (*Clock) Since

func (c *Clock) Since(t time.Time) time.Duration

func (*Clock) Sleep

func (c *Clock) Sleep(d time.Duration)

func (*Clock) Tick

func (c *Clock) Tick(d time.Duration) <-chan time.Time

func (*Clock) Ticker

func (c *Clock) Ticker(d time.Duration) *clockapi.Ticker

func (*Clock) Timer

func (c *Clock) Timer(d time.Duration) *clockapi.Timer

Jump to

Keyboard shortcuts

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