testclock

package
v0.0.0-...-51f9457 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestRecentTimeLocal = time.Date(2016, time.February, 3, 4, 5, 6, 7, time.Local)

TestRecentTimeLocal is like TestTimeLocal, but in the recent past.

View Source
var TestRecentTimeUTC = time.Date(2016, time.February, 3, 4, 5, 6, 7, time.UTC)

TestRecentTimeUTC is like TestTimeUTC, but in the recent past.

View Source
var TestTimeLocal = time.Date(1, time.February, 3, 4, 5, 6, 7, time.Local)

TestTimeLocal is an arbitrary time point in the 'Local' time zone for testing.

It corresponds to a negative Unix timestamp, so it might be inappropriate for some tests. Use 'TestRecentTimeLocal' for more "real" test time in this case.

View Source
var TestTimeUTC = time.Date(1, time.February, 3, 4, 5, 6, 7, time.UTC)

TestTimeUTC is an arbitrary time point in UTC for testing.

It corresponds to a negative Unix timestamp, so it might be inappropriate for some tests. Use 'TestRecentTimeUTC' for more "real" test time in this case.

Functions

func GetTags

func GetTags(t clock.Timer) []string

GetTags returns the tags associated with the specified timer. If the timer has no tags, an empty slice (nil) will be returned.

func HasTags

func HasTags(t clock.Timer, first string, tags ...string) bool

HasTags tests if a given timer has the same tags.

Types

type TestClock

type TestClock interface {
	clock.Clock

	// Set sets the test clock's time.
	Set(time.Time)

	// Add advances the test clock's time.
	Add(time.Duration)

	// SetTimerCallback is a goroutine-safe method to set an instance-wide
	// callback that is invoked when any timer begins.
	SetTimerCallback(TimerCallback)
}

TestClock is a Clock interface with additional methods to help instrument it.

func New

func New(now time.Time) TestClock

New returns a TestClock instance set at the specified time.

func UseTime

func UseTime(ctx context.Context, now time.Time) (context.Context, TestClock)

UseTime instantiates a TestClock and returns a Context that is configured to use that clock, as well as the instantiated clock.

type TimerCallback

type TimerCallback func(time.Duration, clock.Timer)

TimerCallback that can be invoked when a timer has been set. This is useful for sychronizing state when testing.

Jump to

Keyboard shortcuts

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