Back to godoc.org

Package testclock

v0.0.0-...-1557bcf
Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Index

Variables

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

TestRecentTimeLocal is like TestTimeLocal, but in the recent past.

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

TestRecentTimeUTC is like TestTimeUTC, but in the recent past.

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.

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.

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.

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier